Fixes #265 - endianess in Jaeger (#314)

* failing jaeger test

* fixed endianess of bytes
This commit is contained in:
Sergey Kanzhelev 2019-10-27 21:52:06 -07:00 committed by GitHub
parent 5090cf777b
commit 6eb3fe32a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 3 deletions

1
.vscode/tasks.json vendored
View File

@ -13,6 +13,7 @@
},
"args": [
"build",
"${workspaceFolder}/OpenTelemetry.sln",
"/property:GenerateFullPaths=true"
],
"problemMatcher": "$msCompile"

View File

@ -41,8 +41,17 @@ namespace OpenTelemetry.Exporter.Jaeger.Implementation
traceId.CopyTo(bytes);
this.High = BitConverter.ToInt64(bytes, 0);
this.Low = BitConverter.ToInt64(bytes, 8);
if (BitConverter.IsLittleEndian)
{
Array.Reverse(bytes);
this.High = BitConverter.ToInt64(bytes, 8);
this.Low = BitConverter.ToInt64(bytes, 0);
}
else
{
this.High = BitConverter.ToInt64(bytes, 0);
this.Low = BitConverter.ToInt64(bytes, 8);
}
}
public long High { get; set; }

View File

@ -0,0 +1,35 @@
// <copyright file="Intt128Test.cs" company="OpenTelemetry Authors">
// Copyright 2018, OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// </copyright>
using System.Diagnostics;
using OpenTelemetry.Exporter.Jaeger.Implementation;
using Xunit;
namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
{
public class Int128Test
{
[Fact]
public void Int128ConversionWorksAsExpected()
{
var id = ActivityTraceId.CreateFromBytes(new byte[] { 0x1a, 0x0f, 0x54, 0x63, 0x25, 0xa8, 0x56, 0x43, 0x1a, 0x4c, 0x24, 0xea, 0xa8, 0x60, 0xb0, 0xe8 });
var int128 = new Int128(id);
Assert.Equal<long>(unchecked((long)0x1a0f546325a85643), int128.High);
Assert.Equal<long>(unchecked((long)0x1a4c24eaa860b0e8), int128.Low);
}
}
}

View File

@ -41,7 +41,8 @@ namespace OpenTelemetry.Exporter.Jaeger.Tests.Implementation
[Fact]
public async void JaegerThriftIntegrationTest_TAbstractBaseGeneratesConsistentThriftPayload()
{
var validJaegerThriftPayload = Convert.FromBase64String("goEBCWVtaXRCYXRjaBwcGAx0ZXN0IHByb2Nlc3MZHBgQdGVzdF9wcm9jZXNzX3RhZxUAGAp0ZXN0X3ZhbHVlAAAZHBbdlZjkk/C0+ZoBFtCr96fz8ZbpnQEW1KXb/ciQz6OBARaY3JDShc6hzrIBGAROYW1lGRwVABbdlZjkk/C0+ZoBFtCr96fz8ZbpnQEWkKas4ZbKtZyDAQAVAhaAgLPexpa/BRaAnJw5GWwYCXN0cmluZ0tleRUAGAV2YWx1ZQAYB2xvbmdLZXkVBkYCABgIbG9uZ0tleTIVBkYCABgJZG91YmxlS2V5FQInAAAAAAAA8D8AGApkb3VibGVLZXkyFQInAAAAAAAA8D8AGAdib29sS2V5FQQxABksFoCAs97Glr8FGSwYA2tleRUAGAV2YWx1ZQAYC2Rlc2NyaXB0aW9uFQAYBkV2ZW50MQAAFoCAs97Glr8FGSwYA2tleRUAGAV2YWx1ZQAYC2Rlc2NyaXB0aW9uFQAYBkV2ZW50MgAAAAAA");
var validJaegerThriftPayload = Convert.FromBase64String("goEBCWVtaXRCYXRjaBwcGAx0ZXN0IHByb2Nlc3MZHBgQdGVzdF9wcm9jZXNzX3RhZxUAGAp0ZXN0X3ZhbHVlAAAZHBab5cuG2OehhdwBFuPakI2n2cCVLhbUpdv9yJDPo4EBFpjckNKFzqHOsgEYBE5hbWUZHBUAFpvly4bY56GF3AEW49qQjafZwJUuFpCmrOGWyrWcgwEAFQIWgICz3saWvwUWgJycORlsGAlzdHJpbmdLZXkVABgFdmFsdWUAGAdsb25nS2V5FQZGAgAYCGxvbmdLZXkyFQZGAgAYCWRvdWJsZUtleRUCJwAAAAAAAPA/ABgKZG91YmxlS2V5MhUCJwAAAAAAAPA/ABgHYm9vbEtleRUEMQAZLBaAgLPexpa/BRksGANrZXkVABgFdmFsdWUAGAtkZXNjcmlwdGlvbhUAGAZFdmVudDEAABaAgLPexpa/BRksGANrZXkVABgFdmFsdWUAGAtkZXNjcmlwdGlvbhUAGAZFdmVudDIAAAAAAA==");
using (var memoryTransport = new InMemoryTransport())
{
var protocolFactory = new TCompactProtocol.Factory();