Skip to content

Commit

Permalink
fix: handle undefined traceparent
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankcorn committed Mar 28, 2024
1 parent a6a1cd9 commit 390b33a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.


The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased]

* Handle undefined traceparent for step function propagation

## [0.5.2] - 2024-03-28

Expand Down
2 changes: 1 addition & 1 deletion examples/state-machine/packages/functions/src/lambda.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { withOpenTelemetry } from "./tracing";
// import { withOpenTelemetry } from "./tracing";
import { ApiHandler } from "sst/node/api";

export const handler = withOpenTelemetry(ApiHandler(async (_evt) => {
Expand Down
7 changes: 3 additions & 4 deletions examples/state-machine/packages/functions/src/task-two.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { withOpenTelemetry } from "./tracing";
import { ApiHandler } from "sst/node/api";

export const handler = withOpenTelemetry(async (_evt) => {
console.log(_evt)
export const handler = ApiHandler(async (_evt) => {
return {
statusCode: 200,
body: `Hello world. The time is ${new Date().toISOString()}`,
};
});
});
4 changes: 2 additions & 2 deletions src/lambda/propation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function extractContext(service: string, event: any): { parent?: Context,
if (Array.isArray(event)) {
return {
links: event.map((parent) => {
const traceparent = parent._baselime?.traceparent || parent.Payload?._baselime.traceparent;
const traceparent = parent._baselime?.traceparent || parent.Payload?._baselime?.traceparent;
if (!traceparent) {
return
}
Expand All @@ -51,7 +51,7 @@ export function extractContext(service: string, event: any): { parent?: Context,
}).filter(el => el)
}
}
const traceparent = event._baselime?.traceparent || event.Payload?._baselime.traceparent;
const traceparent = event._baselime?.traceparent || event.Payload?._baselime?.traceparent;

return {
parent: propagation.extract(context.active(), { traceparent }, headerGetter)
Expand Down

0 comments on commit 390b33a

Please sign in to comment.