Skip to content

feat(tracing): OTel resource enrichment, semconv HTTP attributes, cached tracers#3857

Merged
lpcox merged 4 commits intomainfrom
copilot/go-fan-go-module-review
Apr 15, 2026
Merged

feat(tracing): OTel resource enrichment, semconv HTTP attributes, cached tracers#3857
lpcox merged 4 commits intomainfrom
copilot/go-fan-go-module-review

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 15, 2026

Applies the quick-win improvements from the go-fan OTel module review: richer resource metadata, stable semconv constants for HTTP span attributes, and cached tracers at construction time.

Resource improvements (internal/tracing/provider.go)

res, err := resource.New(ctx,
    resource.WithTelemetrySDK(),                          // adds otel.library.name/version
    resource.WithSchemaURL(semconv.SchemaURL),            // OTel spec compliance
    resource.WithAttributes(
        semconv.ServiceName(serviceName),
        semconv.ServiceVersion(version.Get()),            // deployment-aware tracing
    ),
    resource.WithProcessPID(),
    resource.WithHost(),
)

Semconv HTTP attribute constants

Replaced raw string attributes with stable semconv v1.26.0 constants across all instrumented files:

Before After
attribute.String("http.method", r.Method) semconv.HTTPRequestMethodKey.String(r.Method)
attribute.String("http.path", r.URL.Path) semconv.URLPathKey.String(r.URL.Path)
attribute.Int("http.status_code", code) semconv.HTTPResponseStatusCodeKey.Int(code)

Affected: internal/tracing/http.go, internal/server/http_helpers.go, internal/server/unified.go, internal/proxy/handler.go.

Cached tracers at construction

UnifiedServer and proxyHandler previously called tracing.Tracer() (→ otel.Tracer(...)) on every request. Both now cache the tracer at construction via a tracer oteltrace.Tracer field, with a getTracer() nil-safe fallback to keep existing tests (which construct these structs directly) working without modification.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /tmp/go-build2146563392/b510/launcher.test /tmp/go-build2146563392/b510/launcher.test -test.testlogfile=/tmp/go-build2146563392/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 6563392/b203/_pk-p ache/go/1.25.8/xgo.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp bin/as -p b/gh-aw-mcpg/int-atomic -lang=go1.25 /opt/hostedtoolc-buildtags go_.�� otlptrace/otlptr-errorsas -trimpath x_amd64/compile -p vendor/golang.ordocker-cli-plugin-metadata -lang=go1.25 x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build4139057404/b514/launcher.test /tmp/go-build4139057404/b514/launcher.test -test.testlogfile=/tmp/go-build4139057404/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /home/REDACTED/.cache/go-build/05/05ba880d21430c45c3563656362c54dda898a477387de95da38a5d091bd8bbf6-d /tmp/go-build2146563392/b392/_pkg_.a -trimpath (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build2146563392/b492/config.test /tmp/go-build2146563392/b492/config.test -test.testlogfile=/tmp/go-build2146563392/b492/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 6563392/b163/_pk-p .cfg x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build4139057404/b496/config.test /tmp/go-build4139057404/b496/config.test -test.testlogfile=/tmp/go-build4139057404/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s -I aw-mcpg/internal/difc/agent.go aw-mcpg/internal/difc/capabilities.go ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet --gdwarf-5 --64 -o ache/go/1.25.8/x64/pkg/tool/linux_amd64/vet -o /tmp/go-build2146563392/b370/_pkg_.a -trimpath 6563392/b378/vet.cfg -p google.golang.or/tmp/go-build3569075202/b428/vet.cfg -lang=go1.24 /opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linu1 (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build2146563392/b510/launcher.test /tmp/go-build2146563392/b510/launcher.test -test.testlogfile=/tmp/go-build2146563392/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 6563392/b203/_pk-p ache/go/1.25.8/xgo.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp bin/as -p b/gh-aw-mcpg/int-atomic -lang=go1.25 /opt/hostedtoolc-buildtags go_.�� otlptrace/otlptr-errorsas -trimpath x_amd64/compile -p vendor/golang.ordocker-cli-plugin-metadata -lang=go1.25 x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build4139057404/b514/launcher.test /tmp/go-build4139057404/b514/launcher.test -test.testlogfile=/tmp/go-build4139057404/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /home/REDACTED/.cache/go-build/05/05ba880d21430c45c3563656362c54dda898a477387de95da38a5d091bd8bbf6-d /tmp/go-build2146563392/b392/_pkg_.a -trimpath (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build2146563392/b510/launcher.test /tmp/go-build2146563392/b510/launcher.test -test.testlogfile=/tmp/go-build2146563392/b510/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 6563392/b203/_pk-p ache/go/1.25.8/xgo.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp bin/as -p b/gh-aw-mcpg/int-atomic -lang=go1.25 /opt/hostedtoolc-buildtags go_.�� otlptrace/otlptr-errorsas -trimpath x_amd64/compile -p vendor/golang.ordocker-cli-plugin-metadata -lang=go1.25 x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build4139057404/b514/launcher.test /tmp/go-build4139057404/b514/launcher.test -test.testlogfile=/tmp/go-build4139057404/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /home/REDACTED/.cache/go-build/05/05ba880d21430c45c3563656362c54dda898a477387de95da38a5d091bd8bbf6-d /tmp/go-build2146563392/b392/_pkg_.a -trimpath (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build2146563392/b519/mcp.test /tmp/go-build2146563392/b519/mcp.test -test.testlogfile=/tmp/go-build2146563392/b519/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true /grpc_binarylog_v1/binarylog.pb.go .cfg x_amd64/compile -o (dns block)
    • Triggering command: /tmp/go-build4139057404/b523/mcp.test /tmp/go-build4139057404/b523/mcp.test -test.testlogfile=/tmp/go-build4139057404/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s -ato�� ry=1 8 x_amd64/vet -errorsas -ifaceassert -nilfunc x_amd64/vet -ato�� -bool -buildtags x_amd64/vet -errorsas -ifaceassert -nilfunc x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 15, 2026 that may be closed by this pull request
4 tasks
- Add semconv.ServiceVersion, resource.WithSchemaURL, resource.WithTelemetrySDK to provider
- Use stable semconv v1.26.0 HTTP constants for span attributes across all files
- Cache tracing.Tracer() at construction time in UnifiedServer and proxyHandler

Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/e47e43a6-f379-4c51-a9ed-3d4390f56df7

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Review OpenTelemetry Go SDK integration in gh-aw feat(tracing): OTel resource enrichment, semconv HTTP attributes, cached tracers Apr 15, 2026
Copilot AI requested a review from lpcox April 15, 2026 14:16
@lpcox lpcox marked this pull request as ready for review April 15, 2026 14:32
Copilot AI review requested due to automatic review settings April 15, 2026 14:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enhances the gateway’s OpenTelemetry tracing by enriching OTEL resources, standardizing HTTP span attributes on stable semantic-convention constants, and reducing per-request overhead by caching tracers on server/handler construction.

Changes:

  • Enrich OTEL resource with SDK metadata, schema URL, and service.version.
  • Replace raw "http.*" attribute strings with semconv/v1.26.0 constants for method/path/status.
  • Cache oteltrace.Tracer instances in UnifiedServer and proxyHandler to avoid repeated otel.Tracer(...) calls.
Show a summary per file
File Description
internal/tracing/provider.go Adds SDK/schema/service-version resource enrichment during provider init.
internal/tracing/http.go Uses semconv HTTP method + URL path keys in the generic HTTP wrapper.
internal/server/unified.go Caches tracer; switches HTTP status attribute to semconv.
internal/server/http_helpers.go Uses semconv HTTP method + URL path keys in server HTTP middleware.
internal/proxy/proxy.go Constructs proxyHandler with a cached tracer.
internal/proxy/handler.go Adds cached tracer + semconv keys for path/status within proxy spans.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comments suppressed due to low confidence (1)

internal/proxy/handler.go:205

  • This span attribute uses semconv.URLPathKey but path may include the query string (it is forwarded upstream as fullPath). url.path should not contain ?query=...; use the raw path (no query) for URLPathKey and optionally capture query/full URL via the appropriate semconv keys.
	fwdCtx, fwdSpan := h.getTracer().Start(ctx, "proxy.backend.forward",
		oteltrace.WithAttributes(
			semconv.URLPathKey.String(path),
			attribute.String("tool.name", toolName),
		),
  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread internal/proxy/handler.go Outdated
Comment thread internal/tracing/http.go
lpcox and others added 2 commits April 15, 2026 07:46
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

[go-fan] Go Module Review: go.opentelemetry.io/otel

3 participants