Skip to content

Commit c5a5589

Browse files
refactor: avoid using magic string
1 parent 665cafa commit c5a5589

File tree

5 files changed

+6
-7
lines changed

5 files changed

+6
-7
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"];
24+
var currentTraceContext = (TraceContext)context.AdditionalContext[TraceContext.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"];
24+
var currentTraceContext = (TraceContext)context.AdditionalContext[TraceContext.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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ namespace Voxel.MiddyNet.Tracing.ApiGatewayMiddleware
66
{
77
public class ApiGatewayHttpApiV2TracingMiddleware : ILambdaMiddleware<APIGatewayHttpApiV2ProxyRequest, APIGatewayHttpApiV2ProxyResponse>
88
{
9-
private const string TraceContextKey = "TraceContext";
109
private const string TraceParentHeaderName = "traceparent";
1110
private const string TraceStateHeaderName = "tracestate";
1211
private const string TraceIdHeaderName = "trace-id";
@@ -23,7 +22,7 @@ public Task Before(APIGatewayHttpApiV2ProxyRequest apiGatewayEvent, MiddyNetCont
2322

2423
var traceContext = TraceContext.Handle(traceParentHeaderValue, traceStateHeaderValue);
2524

26-
context.AdditionalContext.Add(TraceContextKey, traceContext);
25+
context.AdditionalContext.Add(TraceContext.TraceContextKey, traceContext);
2726

2827
context.Logger.EnrichWith(new LogProperty(TraceParentHeaderName, traceContext.TraceParent));
2928
context.Logger.EnrichWith(new LogProperty(TraceStateHeaderName, traceContext.TraceState));

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@ namespace Voxel.MiddyNet.Tracing.ApiGatewayMiddleware
66
{
77
public class ApiGatewayTracingMiddleware : ILambdaMiddleware<APIGatewayProxyRequest, APIGatewayProxyResponse>
88
{
9-
private const string TraceContextKey = "TraceContext";
109
private const string TraceParentHeaderName = "traceparent";
1110
private const string TraceStateHeaderName = "tracestate";
1211
private const string TraceIdHeaderName = "trace-id";
1312

14-
1513
public Task Before(APIGatewayProxyRequest apiGatewayEvent, MiddyNetContext context)
1614
{
1715
var traceParentHeaderValue = string.Empty;
@@ -24,7 +22,7 @@ public Task Before(APIGatewayProxyRequest apiGatewayEvent, MiddyNetContext conte
2422

2523
var traceContext = TraceContext.Handle(traceParentHeaderValue, traceStateHeaderValue);
2624

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

2927
context.Logger.EnrichWith(new LogProperty(TraceParentHeaderName, traceContext.TraceParent));
3028
context.Logger.EnrichWith(new LogProperty(TraceStateHeaderName, traceContext.TraceState));

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

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

0 commit comments

Comments
 (0)