10000 Move span pointer to inferred span; add env var to toggle span pointers by nhulston · Pull Request #607 · DataDog/datadog-lambda-js · GitHub
[go: up one dir, main page]

Skip to content

Move span pointer to inferred span; add env var to toggle span pointers #607

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

Merged
merged 8 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const coldStartTracingEnvVar = "DD_COLD_START_TRACING";
export const minColdStartTraceDurationEnvVar = "DD_MIN_COLD_START_DURATION";
export const coldStartTraceSkipLibEnvVar = "DD_COLD_START_TRACE_SKIP_LIB";
export const localTestingEnvVar = "DD_LOCAL_TESTING";
export const addSpanPointersEnvVar = "DD_TRACE_AWS_ADD_SPAN_POINTERS";

interface GlobalConfig {
/**
Expand Down Expand Up @@ -95,6 +96,7 @@ export const defaultConfig: Config = {
minColdStartTraceDuration: 3,
coldStartTraceSkipLib: "",
localTesting: false,
addSpanPointers: true,
} as const;

export const _metricsQueue: MetricsQueue = new MetricsQueue();
Expand Down Expand Up @@ -412,6 +414,11 @@ function getConfig(userConfig?: Partial<Config>): Config {
config.localTesting = result === "true" || result === "1";
}

if (userConfig === undefined || userConfig.addSpanPointers === undefined) {
const result = getEnvValue(addSpanPointersEnvVar, "true").toLowerCase();
config.addSpanPointers = result === "true";
}

return config;
}

Expand Down
1 change: 1 addition & 0 deletions src/trace/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe("TraceListener", () => {
injectLogContext: false,
minColdStartTraceDuration: 3,
coldStartTraceSkipLib: "",
addSpanPointers: true,
};
const context = {
invokedFunctionArn: "arn:aws:lambda:us-east-1:123456789101:function:my-lambda",
Expand Down
21 changes: 18 additions & 3 deletions src/trace/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ export interface TraceConfig {
* Libraries to ignore from cold start traces
*/
coldStartTraceSkipLib: string;
/**
* Whether to enable span pointers
* @default true
*/
addSpanPointers: boolean;
}

export class TraceListener {
Expand Down Expand Up @@ -137,7 +142,9 @@ export class TraceListener {
this.triggerTags = extractTriggerTags(event, context, eventSource);
this.stepFunctionContext = StepFunctionContextService.instance().context;

this.spanPointerAttributesList = getSpanPointerAttributes(eventSource, event);
if (this.config.addSpanPointers) {
this.spanPointerAttributesList = getSpanPointerAttributes(eventSource, event);
}
}

/**
Expand Down Expand Up @@ -201,9 +208,17 @@ export class TraceListener {
}
}

if (this.wrappedCurrentSpan && this.spanPointerAttributesList) {
let rootSpan = this.inferredSpan;
if (!rootSpan) {
rootSpan = this.wrappedCurrentSpan;
}
if (this.spanPointerAttributesList) {
for (const attributes of this.spanPointerAttributesList) {
this.wrappedCurrentSpan.span.addSpanPointer(attributes.kind, attributes.direction, attributes.hash);
try {
rootSpan.span.addSpanPointer(attributes.kind, attributes.direction, attributes.hash);
} catch (e) {
logDebug("Failed to add span pointer");
}
}
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/span-pointers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function processDynamoDbEvent(event: any): SpanPointerAttributes[] {

const keys = record.dynamodb?.Keys;
const eventSourceARN = record.eventSourceARN;
const tableName = record.eventSourceARN ? getTableNameFromARN(eventSourceARN) : undefined;
const tableName = eventSourceARN ? getTableNameFromARN(eventSourceARN) : undefined;

if (!tableName || !keys) {
logDebug("Unable to calculate hash because of missing parameters.");
Expand Down
Loading
0