Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract Upper64 bit trace ID from extension response #6041

Merged
Merged
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
69b6163
Extract Upper64 bit trace ID from extension response
agocs Sep 16, 2024
42c242a
Use SpanContextPropagator.Instance.Extract()
agocs Sep 24, 2024
94d9f24
replace CreateNewPlaceholderScope with NewCreatePlaceholderScope in t…
agocs Sep 25, 2024
00c5475
Remove createPlaceholderScope
agocs Sep 25, 2024
55245cd
Rename NewCreatePlaceholderScope to CreatePlaceholderscope
agocs Sep 25, 2024
ad19246
Merge branch 'master' into chris.agocs/parse_128_bit_trace_id_from_la…
agocs Sep 25, 2024
cee09c0
Savepoint
agocs Sep 30, 2024
ddd0fb6
Fix test for 128 bit trace IDs
agocs Sep 30, 2024
b300797
Reorganize LambdaCommon a little bit
agocs Sep 30, 2024
7b9bb9f
Merge branch 'master' into chris.agocs/parse_128_bit_trace_id_from_la…
agocs Sep 30, 2024
3fd8cd6
CreatePlaceholderScope takes WebHeaderCollection
agocs Oct 1, 2024
357f279
Merge branch 'chris.agocs/parse_128_bit_trace_id_from_lambda_extensio…
agocs Oct 1, 2024
9fb8fcd
Get empty string array from WebHeadersCollection instead of null
agocs Oct 2, 2024
ad30105
Update tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/L…
agocs Oct 3, 2024
a56874d
Merge branch 'master' into chris.agocs/parse_128_bit_trace_id_from_la…
agocs Oct 3, 2024
d2a6d92
Cherry pick commits from v3
agocs Sep 30, 2024
274d538
Fix test for 128 bit trace IDs
agocs Sep 30, 2024
83362d6
Reorganize LambdaCommon a little bit
agocs Sep 30, 2024
ed98cb1
CreatePlaceholderScope takes WebHeaderCollection
agocs Oct 1, 2024
52ccc64
Get empty string array from WebHeadersCollection instead of null
agocs Oct 2, 2024
60ccc82
Update tracer/src/Datadog.Trace/ClrProfiler/AutoInstrumentation/AWS/L…
agocs Oct 3, 2024
bf5a010
Minor build fixes (#6099)
andrewlock Sep 30, 2024
7376508
[IAST] Fix for VS Edit and Continue (#6097)
daniel-romano-DD Oct 1, 2024
c0c88f4
Remove warning about non-serializable test data (#6102)
bouwkast Oct 1, 2024
1bf0873
[ASM][RCM] Read waf actions per file and remove per file (#6072)
anna-git Oct 2, 2024
758301f
Run CallTargetNativeTests on Windows (#5754)
andrewlock Oct 2, 2024
6e7966a
[ASM] Suspicious attacker blocking (#6057)
NachoEchevarria Oct 2, 2024
2b5c0dc
chore: prefix system tests env vars (#6108)
wconti27 Oct 2, 2024
6f1be32
[Crashtracking] Implement support for Windows (#6088)
kevingosse Oct 3, 2024
587426a
[Crashtracking] Add registry key to installer (#6106)
kevingosse Oct 3, 2024
0ec8f01
[Crashtracking] Remove exception types that are too broad (#6109)
kevingosse Oct 3, 2024
a1838fa
[ASM] Activate api sec by default (#6043)
anna-git Oct 3, 2024
43b2292
[CI Visibility] Fix code coverage enabled tag behavior (#6111)
tonyredondo Oct 3, 2024
a4b1301
[Profiler] Bump libdatadog 13.1 (#6112)
gleocadie Oct 3, 2024
992259d
Update integration test snapshots
agocs Oct 8, 2024
ce40a26
Merge branch 'chris.agocs/parse_128_bit_trace_id_from_lambda_extensio…
agocs Oct 8, 2024
f710538
force ci
agocs Oct 9, 2024
1d962d7
Revert "CreatePlaceholderScope takes WebHeaderCollection"
agocs Oct 16, 2024
2363539
Revert "Reorganize LambdaCommon a little bit"
agocs Oct 16, 2024
c6377c1
Revert "Cherry pick commits from v3"
agocs Oct 16, 2024
f6ef838
CreatePlaceholderScope takes NameValueHeadersCollection
agocs Oct 17, 2024
a898b31
Use StartSpan instead of StartActiveInternal in CreatePlaceholderScope
agocs Oct 21, 2024
83201d8
Update integration test snapshots
agocs Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal abstract class LambdaCommon
private const double ServerlessMaxWaitingFlushTime = 3;
private const string LogLevelEnvName = "DD_LOG_LEVEL";

internal static Scope CreatePlaceholderScope(Tracer tracer, string traceId, string samplingPriority)
internal static Scope CreatePlaceholderScope(Tracer tracer, string traceId, ulong traceIdUpper64, string samplingPriority)
{
Span span;

Expand All @@ -32,8 +32,17 @@ internal static Scope CreatePlaceholderScope(Tracer tracer, string traceId, stri
}
else
{
Log($"creating the placeholder traceId = {traceId}");
span = tracer.StartSpan(PlaceholderOperationName, tags: null, serviceName: PlaceholderServiceName, traceId: (TraceId)Convert.ToUInt64(traceId), addToTraceContext: false);
if (traceIdUpper64 == 0)
{
Log($"creating the placeholder traceId = {traceId}");
span = tracer.StartSpan(PlaceholderOperationName, tags: null, serviceName: PlaceholderServiceName, traceId: (TraceId)Convert.ToUInt64(traceId), addToTraceContext: false);
}
else
{
var traceIdLower64 = Convert.ToUInt64(traceId);
Log($"creating the placeholder traceId = {traceIdUpper64}{traceIdLower64}");
lucaspimentel marked this conversation as resolved.
Show resolved Hide resolved
span = tracer.StartSpan(PlaceholderOperationName, tags: null, serviceName: PlaceholderServiceName, traceId: new TraceId(traceIdUpper64, traceIdLower64), addToTraceContext: false);
}
lucaspimentel marked this conversation as resolved.
Show resolved Hide resolved
}

if (samplingPriority == null)
Expand All @@ -58,15 +67,42 @@ internal static Scope SendStartInvocation(ILambdaExtensionRequest requestBuilder
WriteRequestHeaders(request, context);
var response = (HttpWebResponse)request.GetResponse();
var traceId = response.Headers.Get(HttpHeaderNames.TraceId);
var traceIdUpper64 = GetTraceIdUpper64(response.Headers.Get(HttpHeaderNames.PropagatedTags));
var samplingPriority = response.Headers.Get(HttpHeaderNames.SamplingPriority);
lucaspimentel marked this conversation as resolved.
Show resolved Hide resolved
if (ValidateOkStatus(response))
{
return CreatePlaceholderScope(Tracer.Instance, traceId, samplingPriority);
return CreatePlaceholderScope(Tracer.Instance, traceId, traceIdUpper64, samplingPriority);
}

return null;
}

/// <summary>
/// GetTraceIdUpper64 searches the x-datadog-tags tags for the upper 64 bits of the trace id.
/// Per the 128 bit tracing RFC, the upper 64 bits are stored in the _dd.p.tid tag as a hex string.
/// </summary>
/// <param name="ddTags">The propagated tags from the x-datadog-tags header</param>
/// <returns>the upper 64 bits of the traceId as a ulong</returns>
internal static ulong GetTraceIdUpper64(string ddTags)
{
if (ddTags == null)
{
return 0;
}

var tags = ddTags.Split(',');
foreach (var tag in tags)
{
var keyValue = tag.Trim().Split('=');
if (keyValue.Length == 2 && keyValue[0] == "_dd.p.tid")
{
return Convert.ToUInt64(keyValue[1], 16);
}
}

return 0;
}

internal static void SendEndInvocation(ILambdaExtensionRequest requestBuilder, Scope scope, bool isError, string data)
{
var request = requestBuilder.GetEndInvocationRequest(scope, isError);
Expand Down
Loading