Skip to content

Commit d469586

Browse files
author
Vicenc Garcia
committed
Use trace context key from the middleware
1 parent c5a5589 commit d469586

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

samples/ApiGatewayHttpApiV2Tracing/Voxel.MiddyNet.HttpApiV2TracingSample/ApiGatewayHttpApiV2Tracing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override Task<APIGatewayHttpApiV2ProxyResponse> Handle(APIGatewayHttpA
2121

2222
//If you need to call another system, you need to obtain a traceparent based on the original traceparent
2323
//received but with the ParentId changed
24-
var currentTraceContext = (TraceContext)context.AdditionalContext[TraceContext.TraceContextKey];
24+
var currentTraceContext = (TraceContext)context.AdditionalContext[ApiGatewayHttpApiV2TracingMiddleware.TraceContextKey];
2525
var newTraceContext = TraceContext.MutateParentId(currentTraceContext);
2626

2727
//Now you can use this newTraceContext in your calls

samples/ApiGatewayTracing/Voxel.MiddyNet.ApiGatewayTracingSample/ApiGatewayTracing.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ protected override Task<APIGatewayProxyResponse> Handle(APIGatewayProxyRequest p
2121

2222
//If you need to call another system, you need to obtain a traceparent based on the original traceparent
2323
//received but with the ParentId changed
24-
var currentTraceContext = (TraceContext)context.AdditionalContext[TraceContext.TraceContextKey];
24+
var currentTraceContext = (TraceContext)context.AdditionalContext[ApiGatewayTracingMiddleware.TraceContextKey];
2525
var newTraceContext = TraceContext.MutateParentId(currentTraceContext);
2626

2727
//Now you can use this newTraceContext in your calls

src/Voxel.MiddyNet.Tracing.ApiGatewayMiddleware/ApiGatewayHttpApiV2TracingMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class ApiGatewayHttpApiV2TracingMiddleware : ILambdaMiddleware<APIGateway
1010
private const string TraceStateHeaderName = "tracestate";
1111
private const string TraceIdHeaderName = "trace-id";
1212

13+
public static string TraceContextKey = "TraceContext";
14+
1315
public Task Before(APIGatewayHttpApiV2ProxyRequest apiGatewayEvent, MiddyNetContext context)
1416
{
1517
var traceParentHeaderValue = string.Empty;
@@ -22,7 +24,7 @@ public Task Before(APIGatewayHttpApiV2ProxyRequest apiGatewayEvent, MiddyNetCont
2224

2325
var traceContext = TraceContext.Handle(traceParentHeaderValue, traceStateHeaderValue);
2426

25-
context.AdditionalContext.Add(TraceContext.TraceContextKey, traceContext);
27+
context.AdditionalContext.Add(TraceContextKey, traceContext);
2628

2729
context.Logger.EnrichWith(new LogProperty(TraceParentHeaderName, traceContext.TraceParent));
2830
context.Logger.EnrichWith(new LogProperty(TraceStateHeaderName, traceContext.TraceState));

src/Voxel.MiddyNet.Tracing.ApiGatewayMiddleware/ApiGatewayTracingMiddleware.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class ApiGatewayTracingMiddleware : ILambdaMiddleware<APIGatewayProxyRequ
1010
private const string TraceStateHeaderName = "tracestate";
1111
private const string TraceIdHeaderName = "trace-id";
1212

13+
public static string TraceContextKey = "TraceContext";
14+
1315
public Task Before(APIGatewayProxyRequest apiGatewayEvent, MiddyNetContext context)
1416
{
1517
var traceParentHeaderValue = string.Empty;
@@ -22,7 +24,7 @@ public Task Before(APIGatewayProxyRequest apiGatewayEvent, MiddyNetContext conte
2224

2325
var traceContext = TraceContext.Handle(traceParentHeaderValue, traceStateHeaderValue);
2426

25-
context.AdditionalContext.Add(TraceContext.TraceContextKey, traceContext);
27+
context.AdditionalContext.Add(TraceContextKey, traceContext);
2628

2729
context.Logger.EnrichWith(new LogProperty(TraceParentHeaderName, traceContext.TraceParent));
2830
context.Logger.EnrichWith(new LogProperty(TraceStateHeaderName, traceContext.TraceState));

src/Voxel.MiddyNet.Tracing.Core/TraceContext.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ namespace Voxel.MiddyNet.Tracing.Core
55
{
66
public class TraceContext
77
{
8-
public const string TraceContextKey = "TraceContext";
9-
108
private string version;
119
public string TraceId { get; }
1210
private string parentId;

0 commit comments

Comments
 (0)