Skip to content

AWS SAM & AWS Lambda: pg spans not reported #13975

Closed

Description

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/aws-serverless

SDK Version

8.34.0

Framework Version

SAM CLI 1.125.0, pg 8.13.0, Drizzle ORM 0.34.1

Link to Sentry event

https://wierk.sentry.io/performance/trace/fd08bbde979368bd0e7e26c950fcdd92/?node=ms-6ae4ec7ba851d454&node=txn-dc57263b08454d93b3a3001bda12236e&pageEnd&pageStart&project=4508123298463824&source=traces&statsPeriod=24h&timestamp=1728945399.927

Reproduction Example/SDK Setup

I'd like to configure error reporting and profiling via @sentry/aws-serverless for a project that builds on the AWS SAM framework. AWS SAM offers tooling to build and deploy TypeScript source code to a Node.js AWS Lambda function via CloudFormation. The project uses Drizzle ORM and pg to interact with a database.

I've created a repository containing a minimal reproducible example: https://github.com/ffraenz/aws-sam-ts-pg-sentry.

Steps to Reproduce

Configure, build, and deploy the minimal reproducible example above on AWS and trigger it by clicking "Test" on the AWS Lambda UI in AWS Console. Results show up in the Sentry UI.

Expected Result

The function runs successfully. A Sentry transaction gets reported containing a trace with spans for two HTTP events and two Postgres queries executed via Drizzle.js and pg.

Actual Result

The function runs successfully. A Sentry transaction gets reported containing a trace with spans for two HTTP events but without any spans for pg queries. The missing span explicitly shows as "Missing instrumentation" in the UI. The trace shown in the following screenshot is linked above.

Image

For reference, this is the Sentry.init call from the repository mentioned above:

import * as Sentry from '@sentry/aws-serverless';
import { nodeProfilingIntegration } from '@sentry/profiling-node';

Sentry.init({
    dsn: process.env.SENTRY_DSN,
    integrations: [nodeProfilingIntegration(), Sentry.postgresIntegration()],
    tracesSampleRate: 1.0,
    profilesSampleRate: 1.0,
    debug: true,
});
AWS Lambda logs from AWS CloudWatch
INIT_START Runtime Version: nodejs:20.v39	Runtime Version ARN: arn:aws:lambda:eu-central-1::runtime:83d84646b3540dd38341195452110b2178a7231400ce6bc20c6179e5b297ae04
--
Sentry Logger [log]: Initializing Sentry: process: 2, thread: main.
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: NodeFetch
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: LocalVariablesAsync
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: Modules
Sentry Logger [log]: Integration installed: Aws
Sentry Logger [log]: Integration installed: AwsLambda
Sentry Logger [log]: [Profiling] Profiling integration setup.
Sentry Logger [log]: [Profiling] Span profiler mode enabled.
Sentry Logger [log]: Integration installed: ProfilingIntegration
Sentry Logger [log]: Integration installed: Postgres
Sentry Logger [log]: Running in CommonJS mode.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for diag v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for trace v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for context v1.9.0.
Sentry Logger [debug]: @opentelemetry/api: Registered a global for propagation v1.9.0.
Sentry Logger [debug]: @opentelemetry_sentry-patched/instrumentation-http Applying instrumentation patch for nodejs core module on require hook { module: 'http' }
Sentry Logger [warn]: Failed extracting version /var/task
Sentry Logger [debug]: @opentelemetry/instrumentation-aws-lambda Applying instrumentation patch for nodejs module file on require hook {
module: '/var/task/app.js',
version: undefined,
fileName: 'app',
baseDir: '/var/task'
}
Sentry Logger [debug]: patch handler function
START RequestId: 5b6a8284-c83c-4614-a4cf-e95a8a38123e Version: $LATEST
Sentry Logger [log]: [Tracing] Starting sampled root span
op: < unknown op >
name: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
ID: 434e5358e922b78b
2024-10-14T22:36:34.294Z	5b6a8284-c83c-4614-a4cf-e95a8a38123e	INFO	Batch 0
Sentry Logger [log]: [Profiling] started profiling transaction: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
Sentry Logger [log]: [Tracing] Starting sampled root span
op: function.aws.lambda
name: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
ID: 2627aa12341d8ca8
Sentry Logger [log]: [Profiling] started profiling transaction: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for GET: true
Sentry Logger [log]: [Tracing] Starting sampled span
op: < unknown op >
name: GET
ID: 6ae4ec7ba851d454
parent ID: 2627aa12341d8ca8
root ID: 2627aa12341d8ca8
root op: function.aws.lambda
root description: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "GET" with ID 6ae4ec7ba851d454
Sentry Logger [log]: SpanExporter has 1 unsent spans remaining
2024-10-14T22:36:36.176Z	5b6a8284-c83c-4614-a4cf-e95a8a38123e	INFO	Query: insert into "numbers" ("id", "number", "createdAt", "updatedAt") values (default, $1, default, default), (default, $2, default, default), (default, $3, default, default), (default, $4, default, default), (default, $5, default, default), (default, $6, default, default), (default, $7, default, default), (default, $8, default, default), (default, $9, default, default), (default, $10, default, default), (default, $11, default, default), (default, $12, default, default), (default, $13, default, default), (default, $14, default, default), (default, $15, default, default), (default, $16, default, default), (default, $17, default, default), (default, $18, default, default), (default, $19, default, default), (default, $20, default, default), (default, $21, default, default), (default, $22, default, default), (default, $23, default, default), (default, $24, default, default), (default, $25, default, default), (default, $26, default, default), (default, $27, default, default), (default, $28, default, default), (default, $29, default, default), (default, $30, default, default), (default, $31, default, default), (default, $32, default, default), (default, $33, default, default), (default, $34, default, default), (default, $35, default, default), (default, $36, default, default), (default, $37, default, default), (default, $38, default, default), (default, $39, default, default), (default, $40, default, default), (default, $41, default, default), (default, $42, default, default), (default, $43, default, default), (default, $44, default, default), (default, $45, default, default), (default, $46, default, default), (default, $47, default, default), (default, $48, default, default), (default, $49, default, default), (default, $50, default, default), (default, $51, default, default), (default, $52, default, default), (default, $53, default, default), (default, $54, default, default), (default, $55, default, default), (default, $56, default, default), (default, $57, default, default), (default, $58, default, default), (default, $59, default, default), (default, $60, default, default), (default, $61, default, default), (default, $62, default, default), (default, $63, default, default), (default, $64, default, default), (default, $65, default, default), (default, $66, default, default), (default, $67, default, default), (default, $68, default, default), (default, $69, default, default), (default, $70, default, default), (default, $71, default, default), (default, $72, default, default), (default, $73, default, default), (default, $74, default, default), (default, $75, default, default), (default, $76, default, default), (default, $77, default, default), (default, $78, default, default), (default, $79, default, default), (default, $80, default, default), (default, $81, default, default), (default, $82, default, default), (default, $83, default, default), (default, $84, default, default), (default, $85, default, default), (default, $86, default, default), (default, $87, default, default), (default, $88, default, default), (default, $89, default, default), (default, $90, default, default), (default, $91, default, default), (default, $92, default, default), (default, $93, default, default), (default, $94, default, default), (default, $95, default, default), (default, $96, default, default), (default, $97, default, default), (default, $98, default, default), (default, $99, default, default), (default, $100, default, default), (default, $101, default, default), (default, $102, default, default), (default, $103, default, default), (default, $104, default, default), (default, $105, default, default), (default, $106, default, default), (default, $107, default, default), (default, $108, default, default), (default, $109, default, default), (default, $110, default, default), (default, $111, default, default), (default, $112, default, default), (default, $113, default, default), (default, $114, default, default), (default, $115, default, default), (default, $116, default, default), (default, $117, default, default), (default, $118, default, default), (default, $119, default, default), (default, $120, default, default), (default, $121, default, default), (default, $122, default, default), (default, $123, default, default), (default, $124, default, default), (default, $125, default, default), (default, $126, default, default), (default, $127, default, default), (default, $128, default, default), (default, $129, default, default), (default, $130, default, default), (default, $131, default, default), (default, $132, default, default), (default, $133, default, default), (default, $134, default, default), (default, $135, default, default), (default, $136, default, default), (default, $137, default, default), (default, $138, default, default), (default, $139, default, default), (default, $140, default, default), (default, $141, default, default), (default, $142, default, default), (default, $143, default, default), (default, $144, default, default), (default, $145, default, default), (default, $146, default, default), (default, $147, default, default), (default, $148, default, default), (default, $149, default, default), (default, $150, default, default), (default, $151, default, default), (default, $152, default, default), (default, $153, default, default), (default, $154, default, default), (default, $155, default, default), (default, $156, default, default), (default, $157, default, default), (default, $158, default, default), (default, $159, default, default), (default, $160, default, default), (default, $161, default, default), (default, $162, default, default), (default, $163, default, default), (default, $164, default, default), (default, $165, default, default), (default, $166, default, default), (default, $167, default, default), (default, $168, default, default), (default, $169, default, default), (default, $170, default, default), (default, $171, default, default), (default, $172, default, default), (default, $173, default, default), (default, $174, default, default), (default, $175, default, default), (default, $176, default, default), (default, $177, default, default), (default, $178, default, default), (default, $179, default, default), (default, $180, default, default), (default, $181, default, default), (default, $182, default, default), (default, $183, default, default), (default, $184, default, default), (default, $185, default, default), (default, $186, default, default), (default, $187, default, default), (default, $188, default, default), (default, $189, default, default), (default, $190, default, default), (default, $191, default, default), (default, $192, default, default), (default, $193, default, default), (default, $194, default, default), (default, $195, default, default), (default, $196, default, default), (default, $197, default, default), (default, $198, default, default), (default, $199, default, default), (default, $200, default, default), (default, $201, default, default) -- params: [4, 4, 1, 3, 5, 1, 4, 6, 4, 2, 2, 4, 1, 4, 5, 6, 5, 5, 5, 6, 1, 5, 2, 2, 4, 3, 3, 3, 2, 2, 4, 4, 1, 2, 4, 2, 2, 4, 5, 2, 3, 6, 5, 2, 2, 5, 1, 2, 6, 2, 6, 5, 1, 6, 3, 2, 2, 3, 1, 4, 4, 5, 4, 2, 4, 5, 1, 5, 4, 4, 3, 2, 5, 2, 4, 2, 6, 5, 4, 5, 4, 3, 5, 2, 2, 5, 5, 5, 2, 4, 3, 3, 4, 5, 2, 5, 1, 2, 4, 4, 2, 1, 5, 2, 4, 4, 5, 4, 4, 2, 3, 4, 1, 5, 2, 2, 4, 6, 1, 1, 1, 2, 3, 2, 4, 1, 5, 6, 5, 5, 2, 3, 4, 5, 2, 4, 3, 5, 5, 6, 1, 4, 3, 1, 4, 5, 4, 6, 5, 5, 3, 1, 5, 6, 4, 2, 3, 5, 4, 6, 3, 1, 6, 6, 2, 4, 1, 2, 4, 2, 3, 6, 3, 6, 1, 2, 4, 5, 1, 4, 4, 1, 6, 1, 4, 6, 6, 2, 5, 3, 1, 2, 1, 6, 3, 6, 2, 5, 2, 3, 0]
2024-10-14T22:36:38.608Z	5b6a8284-c83c-4614-a4cf-e95a8a38123e	INFO	Batch 1
Sentry Logger [log]: [Tracing] Inheriting parent's sampled decision for GET: true
Sentry Logger [log]: [Tracing] Starting sampled span
op: < unknown op >
name: GET
ID: 233e958452256270
parent ID: 2627aa12341d8ca8
root ID: 2627aa12341d8ca8
root op: function.aws.lambda
root description: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
Sentry Logger [log]: [Tracing] Finishing "< unknown op >" span "GET" with ID 233e958452256270
Sentry Logger [log]: SpanExporter has 2 unsent spans remaining
2024-10-14T22:36:39.790Z	5b6a8284-c83c-4614-a4cf-e95a8a38123e	INFO	Query: insert into "numbers" ("id", "number", "createdAt", "updatedAt") values (default, $1, default, default), (default, $2, default, default), (default, $3, default, default), (default, $4, default, default), (default, $5, default, default), (default, $6, default, default), (default, $7, default, default), (default, $8, default, default), (default, $9, default, default), (default, $10, default, default), (default, $11, default, default), (default, $12, default, default), (default, $13, default, default), (default, $14, default, default), (default, $15, default, default), (default, $16, default, default), (default, $17, default, default), (default, $18, default, default), (default, $19, default, default), (default, $20, default, default), (default, $21, default, default), (default, $22, default, default), (default, $23, default, default), (default, $24, default, default), (default, $25, default, default), (default, $26, default, default), (default, $27, default, default), (default, $28, default, default), (default, $29, default, default), (default, $30, default, default), (default, $31, default, default), (default, $32, default, default), (default, $33, default, default), (default, $34, default, default), (default, $35, default, default), (default, $36, default, default), (default, $37, default, default), (default, $38, default, default), (default, $39, default, default), (default, $40, default, default), (default, $41, default, default), (default, $42, default, default), (default, $43, default, default), (default, $44, default, default), (default, $45, default, default), (default, $46, default, default), (default, $47, default, default), (default, $48, default, default), (default, $49, default, default), (default, $50, default, default), (default, $51, default, default), (default, $52, default, default), (default, $53, default, default), (default, $54, default, default), (default, $55, default, default), (default, $56, default, default), (default, $57, default, default), (default, $58, default, default), (default, $59, default, default), (default, $60, default, default), (default, $61, default, default), (default, $62, default, default), (default, $63, default, default), (default, $64, default, default), (default, $65, default, default), (default, $66, default, default), (default, $67, default, default), (default, $68, default, default), (default, $69, default, default), (default, $70, default, default), (default, $71, default, default), (default, $72, default, default), (default, $73, default, default), (default, $74, default, default), (default, $75, default, default), (default, $76, default, default), (default, $77, default, default), (default, $78, default, default), (default, $79, default, default), (default, $80, default, default), (default, $81, default, default), (default, $82, default, default), (default, $83, default, default), (default, $84, default, default), (default, $85, default, default), (default, $86, default, default), (default, $87, default, default), (default, $88, default, default), (default, $89, default, default), (default, $90, default, default), (default, $91, default, default), (default, $92, default, default), (default, $93, default, default), (default, $94, default, default), (default, $95, default, default), (default, $96, default, default), (default, $97, default, default), (default, $98, default, default), (default, $99, default, default), (default, $100, default, default), (default, $101, default, default), (default, $102, default, default), (default, $103, default, default), (default, $104, default, default), (default, $105, default, default), (default, $106, default, default), (default, $107, default, default), (default, $108, default, default), (default, $109, default, default), (default, $110, default, default), (default, $111, default, default), (default, $112, default, default), (default, $113, default, default), (default, $114, default, default), (default, $115, default, default), (default, $116, default, default), (default, $117, default, default), (default, $118, default, default), (default, $119, default, default), (default, $120, default, default), (default, $121, default, default), (default, $122, default, default), (default, $123, default, default), (default, $124, default, default), (default, $125, default, default), (default, $126, default, default), (default, $127, default, default), (default, $128, default, default), (default, $129, default, default), (default, $130, default, default), (default, $131, default, default), (default, $132, default, default), (default, $133, default, default), (default, $134, default, default), (default, $135, default, default), (default, $136, default, default), (default, $137, default, default), (default, $138, default, default), (default, $139, default, default), (default, $140, default, default), (default, $141, default, default), (default, $142, default, default), (default, $143, default, default), (default, $144, default, default), (default, $145, default, default), (default, $146, default, default), (default, $147, default, default), (default, $148, default, default), (default, $149, default, default), (default, $150, default, default), (default, $151, default, default), (default, $152, default, default), (default, $153, default, default), (default, $154, default, default), (default, $155, default, default), (default, $156, default, default), (default, $157, default, default), (default, $158, default, default), (default, $159, default, default), (default, $160, default, default), (default, $161, default, default), (default, $162, default, default), (default, $163, default, default), (default, $164, default, default), (default, $165, default, default), (default, $166, default, default), (default, $167, default, default), (default, $168, default, default), (default, $169, default, default), (default, $170, default, default), (default, $171, default, default), (default, $172, default, default), (default, $173, default, default), (default, $174, default, default), (default, $175, default, default), (default, $176, default, default), (default, $177, default, default), (default, $178, default, default), (default, $179, default, default), (default, $180, default, default), (default, $181, default, default), (default, $182, default, default), (default, $183, default, default), (default, $184, default, default), (default, $185, default, default), (default, $186, default, default), (default, $187, default, default), (default, $188, default, default), (default, $189, default, default), (default, $190, default, default), (default, $191, default, default), (default, $192, default, default), (default, $193, default, default), (default, $194, default, default), (default, $195, default, default), (default, $196, default, default), (default, $197, default, default), (default, $198, default, default), (default, $199, default, default), (default, $200, default, default), (default, $201, default, default) -- params: [1, 3, 6, 6, 1, 1, 4, 4, 1, 3, 2, 2, 6, 1, 6, 6, 3, 5, 5, 2, 6, 1, 2, 1, 6, 3, 1, 5, 3, 4, 5, 4, 5, 3, 2, 3, 1, 2, 6, 5, 6, 1, 3, 1, 1, 2, 1, 5, 2, 5, 2, 3, 3, 5, 1, 1, 6, 6, 3, 5, 5, 3, 5, 1, 5, 2, 2, 6, 2, 1, 5, 4, 3, 1, 1, 3, 1, 6, 5, 3, 4, 2, 4, 5, 1, 3, 1, 3, 1, 6, 4, 4, 5, 6, 6, 4, 6, 2, 2, 3, 2, 1, 1, 6, 3, 1, 3, 6, 5, 2, 1, 6, 5, 4, 4, 4, 5, 3, 3, 5, 6, 6, 5, 3, 3, 5, 3, 5, 5, 5, 4, 2, 4, 1, 6, 2, 3, 2, 6, 2, 3, 1, 1, 1, 6, 5, 6, 3, 5, 4, 1, 3, 3, 4, 1, 1, 2, 3, 3, 5, 4, 5, 3, 3, 1, 2, 2, 4, 6, 2, 6, 6, 1, 4, 4, 4, 2, 2, 6, 3, 2, 6, 3, 5, 1, 5, 1, 2, 5, 2, 5, 5, 3, 2, 4, 2, 3, 3, 3, 5, 0]
Sentry Logger [log]: [Tracing] Finishing "function.aws.lambda" root span "aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N" with ID 2627aa12341d8ca8
Sentry Logger [log]: [Profiling] stopped profiling of transaction: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
Sentry Logger [log]: SpanExporter exported 3 spans, 0 unsent spans remaining
Sentry Logger [log]: Flushing outcomes...
Sentry Logger [log]: No outcomes to send
Sentry Logger [log]: [Tracing] Finishing "function.aws.lambda" root span "aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N" with ID 434e5358e922b78b
Sentry Logger [log]: [Profiling] stopped profiling of transaction: aws-sam-ts-pg-sentry-HelloWorldFunction-KrbK1K8cre4N
Sentry Logger [error]: Spans may not be exported for the lambda function because we are not force flushing before callback.
Sentry Logger [error]: Metrics may not be exported for the lambda function because we are not force flushing before callback.
END RequestId: 5b6a8284-c83c-4614-a4cf-e95a8a38123e
REPORT RequestId: 5b6a8284-c83c-4614-a4cf-e95a8a38123e	Duration: 7404.69 ms	Billed Duration: 7405 ms	Memory Size: 128 MB	Max Memory Used: 119 MB	Init Duration: 532.32 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Package: aws-serverlessIssues related to the Sentry AWS Serverless SDK

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions