-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Tracing] Add test and endpoints to test OTEL Drop-In Support of the …
…OpenTelemetry Propagators API (#3782)
- Loading branch information
1 parent
b0f3126
commit 81292dd
Showing
24 changed files
with
486 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Unless explicitly stated otherwise all files in this repository are licensed under the the Apache License Version 2.0. | ||
# This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
# Copyright 2024 Datadog, Inc. | ||
|
||
import json | ||
from utils import weblog, interfaces, scenarios, features, incomplete_test_app | ||
|
||
|
||
@features.otel_propagators_api | ||
@scenarios.apm_tracing_e2e_otel | ||
class Test_Otel_Context_Propagation_Default_Propagator_Api: | ||
def setup_propagation_extract(self): | ||
extract_headers = { | ||
"traceparent": "00-11111111111111110000000000000002-000000000000000a-01", | ||
"tracestate": "dd=s:2;p:000000000000000a,foo=1", | ||
"baggage": "foo=1", | ||
} | ||
self.r = weblog.get("/otel_drop_in_default_propagator_extract", headers=extract_headers) | ||
|
||
@incomplete_test_app(library="nodejs", reason="Node.js extract endpoint doesn't seem to be working.") | ||
@incomplete_test_app(library="ruby", reason="Ruby extract seems to fail even though it should be supported") | ||
def test_propagation_extract(self): | ||
content = json.loads(self.r.text) | ||
|
||
assert content["trace_id"] == 2 | ||
assert content["span_id"] == 10 | ||
assert content["tracestate"] and not content["tracestate"].isspace() | ||
# assert content["baggage"] and not content["baggage"].isspace() | ||
|
||
def setup_propagation_inject(self): | ||
inject_headers = { | ||
"baggage": "foo=2", | ||
} | ||
self.r = weblog.get("/otel_drop_in_default_propagator_inject") | ||
|
||
@incomplete_test_app(library="nodejs", reason="Node.js inject endpoint doesn't seem to be working.") | ||
def test_propagation_inject(self): | ||
content = json.loads(self.r.text) | ||
|
||
assert content["traceparent"] and not content["traceparent"].isspace() | ||
# assert content["baggage"] and not content["baggage"].isspace() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
utils/build/docker/dotnet/weblog/Endpoints/OtelDropInEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Text.Json; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Http; | ||
using OpenTelemetry; | ||
using OpenTelemetry.Context.Propagation; | ||
|
||
namespace weblog | ||
{ | ||
public class OtelDropInEndpoint : ISystemTestEndpoint | ||
{ | ||
public void Register(Microsoft.AspNetCore.Routing.IEndpointRouteBuilder routeBuilder) | ||
{ | ||
routeBuilder.MapGet("/otel_drop_in_default_propagator_extract", async context => | ||
{ | ||
var parentContext = OpenTelemetryInstrumentation.Propagator.Extract(default, context.Request.Headers, (carrier, key) => | ||
{ | ||
return carrier.TryGetValue(key, out var value) && value.Count >= 1 ? new[] { value[0] } : null; | ||
}); | ||
|
||
var ddTraceId = Convert.ToUInt64(parentContext.ActivityContext.TraceId.ToHexString().Substring(16), 16); | ||
var ddSpanId = Convert.ToUInt64(parentContext.ActivityContext.SpanId.ToHexString(), 16); | ||
|
||
var data = new | ||
{ | ||
trace_id = ddTraceId, | ||
span_id = ddSpanId, | ||
tracestate = parentContext.ActivityContext.TraceState, | ||
baggage = parentContext.Baggage | ||
}; | ||
|
||
await context.Response.WriteAsync(JsonSerializer.Serialize(data)); | ||
}); | ||
|
||
routeBuilder.MapGet("/otel_drop_in_default_propagator_inject", async context => | ||
{ | ||
var headersDict = new Dictionary<string,string>(); | ||
OpenTelemetryInstrumentation.Propagator.Inject(new PropagationContext(Activity.Current.Context, Baggage.Current), headersDict, (carrier, key, value) => | ||
{ | ||
carrier[key] = value; | ||
}); | ||
|
||
await context.Response.WriteAsync(JsonSerializer.Serialize(headersDict)); | ||
}); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
utils/build/docker/dotnet/weblog/OpenTelemetryInstrumentation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Diagnostics; | ||
using OpenTelemetry.Context.Propagation; | ||
|
||
namespace weblog | ||
{ | ||
public static class OpenTelemetryInstrumentation | ||
{ | ||
public static TextMapPropagator Propagator { get; } = Propagators.DefaultTextMapPropagator; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.