Skip to content

Enhance Synthetic Span Service Representation #655

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions src/trace/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export class TraceListener {
options.service = "aws.lambda";
if (this.context) {
options.resource = this.context.functionName;
options.service = this.context.functionName;
}
return this.tracerWrapper.wrap("aws.lambda", options, func);
}
Expand Down
40 changes: 25 additions & 15 deletions src/trace/span-inferrer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ export class SpanInferrer {
return "sync";
}

static determineServiceName(specificKey: string, genericKey: string, fallback: string): string {
return this.serviceMapping[specificKey] || this.serviceMapping[genericKey] || fallback;
static determineServiceName(specificKey: string, genericKey: string, extractedKey: string, fallback: string): string {
return this.serviceMapping[specificKey] ||
this.serviceMapping[genericKey] ||
(extractedKey?.trim() ? extractedKey : fallback);
}

createInferredSpanForApiGateway(
Expand All @@ -104,7 +106,7 @@ export class SpanInferrer {
}
const resourceName = [method || domain, resourcePath].join(" ");
const apiId = event.requestContext.apiId || "";
const serviceName = SpanInferrer.determineServiceName(apiId, "lambda_api_gateway", domain);
const serviceName = SpanInferrer.determineServiceName(apiId, "lambda_api_gateway", domain, "api_gateway");

options.tags = {
operation_name: "aws.apigateway",
Expand All @@ -114,9 +116,10 @@ export class SpanInferrer {
request_id: context?.awsRequestId,
service: serviceName,
"service.name": serviceName,
"span.type": "http",
"span.type": "web",
"resource.name": resourceName,
"peer.service": this.service,
"span.kind": "server",
apiid: apiId,
_inferred_span: {
tag_source: "self",
Expand Down Expand Up @@ -201,7 +204,7 @@ export class SpanInferrer {
}
const resourceName = [method || domain, path].join(" ");
const apiId: string = event.requestContext.apiId || "";
const serviceName: string = SpanInferrer.determineServiceName(apiId, "lambda_url", domain);
const serviceName: string = SpanInferrer.determineServiceName(apiId, "lambda_url", domain, "lambda_url");

options.tags = {
operation_name: "aws.lambda.url",
Expand All @@ -212,9 +215,10 @@ export class SpanInferrer {
request_id: context?.awsRequestId,
service: serviceName,
"service.name": serviceName,
"span.type": "http",
"span.type": "web",
"resource.name": resourceName,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "sync",
Expand All @@ -241,7 +245,7 @@ export class SpanInferrer {
const { eventSourceARN, eventName, eventVersion, eventID, dynamodb } = referenceRecord;
const [tableArn, tableName] = eventSourceARN?.split("/") || ["", ""];
const resourceName = `${eventName} ${tableName}`;
const serviceName = SpanInferrer.determineServiceName(tableName, "lambda_dynamodb", "aws.dynamodb");
const serviceName = SpanInferrer.determineServiceName(tableName, "lambda_dynamodb", tableName, "dynamodb");
options.tags = {
operation_name: "aws.dynamodb",
tablename: tableName,
Expand All @@ -252,6 +256,7 @@ export class SpanInferrer {
"span.type": "web",
"resource.name": resourceName,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "async",
Expand Down Expand Up @@ -296,16 +301,17 @@ export class SpanInferrer {

const topicName = TopicArn?.split(":").pop() || "";
const resourceName = topicName;
const serviceName = SpanInferrer.determineServiceName(topicName, "lambda_sns", "sns");
const serviceName = SpanInferrer.determineServiceName(topicName, "lambda_sns", topicName, "sns");
options.tags = {
operation_name: "aws.sns",
resource_names: resourceName,
request_id: context?.awsRequestId,
service: serviceName,
"service.name": serviceName,
"span.type": "sns",
"span.type": "web",
"resource.name": resourceName,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "async",
Expand Down Expand Up @@ -347,16 +353,17 @@ export class SpanInferrer {
} = referenceRecord;
const queueName = eventSourceARN?.split(":").pop() || "";
const resourceName = queueName;
const serviceName = SpanInferrer.determineServiceName(queueName, "lambda_sqs", "sqs");
const serviceName = SpanInferrer.determineServiceName(queueName, "lambda_sqs", queueName, "sqs");
options.tags = {
operation_name: "aws.sqs",
resource_names: resourceName,
request_id: context?.awsRequestId,
service: serviceName,
"service.name": serviceName,
"span.type": "web",
"span.type": "queue",
"resource.name": resourceName,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "async",
Expand Down Expand Up @@ -411,9 +418,9 @@ export class SpanInferrer {
eventVersion,
eventID,
} = referenceRecord;
const streamName = eventSourceARN?.split(":").pop() || "";
const streamName = (eventSourceARN?.split(":").pop() || "").replace(/^stream\//, '');
const shardId = eventID.split(":").pop();
const serviceName = SpanInferrer.determineServiceName(streamName, "lambda_kinesis", "kinesis");
const serviceName = SpanInferrer.determineServiceName(streamName, "lambda_kinesis", streamName, "kinesis");
options.tags = {
operation_name: "aws.kinesis",
resource_names: streamName,
Expand All @@ -423,6 +430,7 @@ export class SpanInferrer {
"span.type": "web",
"resource.name": streamName,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "async",
Expand Down Expand Up @@ -461,7 +469,7 @@ export class SpanInferrer {
eventTime,
eventName,
} = referenceRecord;
const serviceName = SpanInferrer.determineServiceName(bucketName, "lambda_s3", "s3");
const serviceName = SpanInferrer.determineServiceName(bucketName, "lambda_s3", bucketName, "s3");
options.tags = {
operation_name: "aws.s3",
resource_names: bucketName,
Expand All @@ -471,6 +479,7 @@ export class SpanInferrer {
"span.type": "web",
"resource.name": bucketName,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "async",
Expand Down Expand Up @@ -499,7 +508,7 @@ export class SpanInferrer {
): SpanWrapper {
const options: SpanOptions = {};
const { time, source } = event as EventBridgeEvent<any, any>;
const serviceName = SpanInferrer.determineServiceName(source, "lambda_eventbridge", "eventbridge");
const serviceName = SpanInferrer.determineServiceName(source, "lambda_eventbridge", source, "eventbridge");
options.tags = {
operation_name: "aws.eventbridge",
resource_names: source,
Expand All @@ -509,6 +518,7 @@ export class SpanInferrer {
"span.type": "web",
"resource.name": source,
"peer.service": this.service,
"span.kind": "server",
_inferred_span: {
tag_source: "self",
synchronicity: "async",
Expand Down
Loading