Skip to content

feat: add OpenTelemetry-aware scaffolding to new:lambda, new:service and new:domain [DEV-542]#203

Merged
negarciacamilo merged 2 commits into
mainfrom
feat/otel-scaffolding-support
May 18, 2026
Merged

feat: add OpenTelemetry-aware scaffolding to new:lambda, new:service and new:domain [DEV-542]#203
negarciacamilo merged 2 commits into
mainfrom
feat/otel-scaffolding-support

Conversation

@negarciacamilo

Copy link
Copy Markdown
Contributor

Description

Scaffolding commands in draft-cli had X-Ray tracing hardcoded across all generated templates, making them incompatible with services already migrated to OpenTelemetry. This PR aligns the scaffolding output with the observability standard established in the api repo: OTEL for new services and domains, and smart auto-detection for lambdas added to existing services.

Task Context

What is the current behavior?

  • new:service always generates serverless.yml with X-Ray tracing (tracing: lambda: true), the serverless-plugin-datadog plugin, and no OTEL environment variables or ADOT collector layer.
  • new:lambda always generates bootstrap handlers using tracer.BeginSubSegment from framev2/pkg/tracer, regardless of whether the target service uses OTEL or X-Ray.
  • new:domain generates service and repository layers with tracer.BeginSubSegment throughout, including repository methods where the DB driver already instruments automatically.
  • All select prompts (service list, lambda types, etc.) render in non-deterministic map iteration order.

What is the new behavior?

new:service — always OTEL:

  • serverless.yml uses build tag "lambda.norpc,otel", sets tracing: false/false, configures otelFunctionLayers (ADOT collector + DD Extension), and removes serverless-plugin-datadog.
  • environment.yml includes all required DD_* and OTEL_* variables.
  • Generates config/otel-layer/collector.yaml with the ADOT → Datadog pipeline.
  • Initial helloworld lambda includes layers: ${self:custom.otelFunctionLayers} in its lambda-config.yml.

new:lambda — smart detection:

  • Reads the target service's serverless.yml and checks for the "lambda.norpc,otel" build tag via project.IsOtelService().
  • If OTEL: bootstrap uses oteltracer.StartSpan() with domain/layer attributes and layers in lambda-config.yml.
  • If X-Ray: bootstrap uses tracer.BeginSubSegment() (existing behavior preserved).
  • Applies to all 6 lambda types: plain, http, sqs, cron, snssqs, custom.

new:domain — always OTEL:

  • Service layer uses oteltracer.StartSpan() with ServiceSpanName, Domain, and Layer attributes.
  • Repository layer removes all explicit spans — the OTel DB driver instrumentation handles them automatically.
  • Applies to both postgres and dynamo variants.

Select prompts:

  • All select inputs now sort options alphabetically before rendering, giving a consistent and navigable list.

Additional Context

Adds 29 template syntax tests in internal/templates/templates_test.go that render every template with representative inputs and validate the output using go/parser (Go files) and gopkg.in/yaml.v3 (YAML files). No files are written to disk — all validation happens in memory. Tests cover all lambda types × OTEL/X-Ray, service templates, and domain templates (postgres + dynamo).

github-actions Bot added 2 commits May 18, 2026 15:08
…folding

- new:lambda auto-detects OTEL vs X-Ray by reading the parent service's
  serverless.yml build tag; bootstrap templates branch on UseOtel for
  all lambda types (plain, http, sqs, cron, snssqs, custom)
- new:service always generates OTEL config: build tag "lambda.norpc,otel",
  tracing disabled, otelFunctionLayers, ADOT collector layer, and all
  required DD_* / OTEL_* environment variables
- new:domain service layer uses oteltracer.StartSpan(); repository layer
  removes X-Ray spans (driver instrumentation handles them automatically)
- adds 29 template syntax tests covering all lambda types x OTEL/X-Ray,
  service templates, and domain templates (postgres + dynamo)
…alphabetically

- all lambda-config.yml templates now include layers: \${self:custom.otelFunctionLayers}
  when UseOtel is true, required for ADOT collector and DD extension to attach
- Select input now sorts options alphabetically before rendering, making
  service and type lists consistent and easier to navigate
@negarciacamilo negarciacamilo marked this pull request as ready for review May 18, 2026 18:18
@negarciacamilo negarciacamilo merged commit deeb420 into main May 18, 2026
3 checks passed
@negarciacamilo negarciacamilo deleted the feat/otel-scaffolding-support branch May 18, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants