Skip to content

feat(telemetry): export application logs over OTLP through the otelzap bridge - #321

Merged
M0Rf30 merged 2 commits into
mainfrom
feat/otlp-logs-bridge
Oct 28, 2026
Merged

M0Rf30 merged 2 commits into
mainfrom
feat/otlp-logs-bridge

Conversation

@gjed

@gjed gjed commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Closes #192.

Application logs go over OTLP through go.opentelemetry.io/contrib/bridges/otelzap (v0.21.0, the same contrib release as the pinned bridges/prometheus v0.72.0), on the log provider telemetry.Setup already installs (#224), only when telemetry.otlp.logs / OTEL_LOGS_EXPORTER=otlp is on.

What changes

  • logger.Tee tees the application logger with the otelzap core on the application scope github.com/openartifact/openartifact, filtered at the logger's level (no debug records at info). cmd/server swaps in the teed logger right after telemetry.Setup. The stdout/file output does not change.
  • Correlation (gjed's point): telemetry.LogFields(ctx) now also returns ctx in a zapcore.SkipType field. Encoders never write a skip field, so stdout lines are byte-identical; otelzap v0.21.0 takes any context.Context field value as the emit context, so the record carries the request span's real TraceID/SpanID, not only trace_id/span_id attributes.
  • Severity comes from the bridge, service.* resource attributes from the provider, drop counting from the feat(telemetry): count dropped OTLP log records and test against a real collector #304 processor: nothing parallel built.
  • The exporter error handler keeps the un-teed logger, so collector errors are never fed back into the export queue.
  • Docs: logs section of docs/operations/monitoring.md, the config reference (regenerated) and the example files. docker/otel-collector.yaml already has a logs pipeline (otlp → memory_limiter, batch → otlp_http), so it is unchanged.

Tests

  • tests/integration: TestOTLPRequestLogsCarryTheRequestSpan serves a request through telemetry.HTTPMiddleware, TracingMiddleware and LoggingMiddleware with a handler log line, against a real collector (otelcoltest), and asserts that each record's traceId/spanId equals the exported server span, with INFO severity and the provider's service.name. With the ctx field removed from LogFields it fails (record ids /, want the request span …).
  • Unit: TestLogCoreEmitsUnderTheLoggedSpan (record ids, severity and scope; stdout line has exactly the old fields), TestTeeWritesBothAtTheLoggerLevel.

Local: make lint (only the existing pkg/rpm/dependencies.go:72 nolintlint, also on main), make test, make test-integration (DB/S3-gated tests skipped locally), make deadcode, make docs-gen, make docs-check.

Known limits

  • Only the HTTP request line is written with the request context. Every other request-path log call has no ctx: no trace/span id over OTLP (and no trace_id on stdout). Inventory below (1107 logger calls in 152 files of the request-serving packages; it also counts some startup/background calls, such as auth bootstrap and the proxy cache).
  • panic recovered would gain nothing from ctx: RecoveryMiddleware is mounted outside telemetry.HTTPMiddleware, so its request has no span.
  • Records also carry trace_id/span_id as string attributes, because they are the stdout fields; removing them from OTLP only would need a field-filtering core.
Log call sites without ctx, per file
File Calls
internal/api/admin_ai.go 5
internal/api/admin_apk_key.go 2
internal/api/admin_audit.go 1
internal/api/admin_gpg.go 4
internal/api/admin_groups.go 2
internal/api/admin_recovery.go 1
internal/api/admin_replication.go 2
internal/api/admin_sso.go 12
internal/api/admin_storage.go 23
internal/api/admin_storage_primary.go 3
internal/api/admin_tiering.go 2
internal/api/admin_tokens.go 1
internal/api/admin_users.go 3
internal/api/ai.go 4
internal/api/artifact_detail.go 2
internal/api/attestation_attach.go 11
internal/api/attestation.go 5
internal/api/audit_export.go 2
internal/api/audit_subjects.go 1
internal/api/auth_handlers.go 10
internal/api/backup.go 9
internal/api/branding.go 5
internal/api/bundles_authz.go 4
internal/api/bundles.go 8
internal/api/bundles_promote.go 2
internal/api/bundles_signing.go 5
internal/api/cleanup.go 2
internal/api/delta.go 8
internal/api/dependency_track.go 15
internal/api/docker_gc.go 1
internal/api/license_artifact.go 2
internal/api/maven_parent_license.go 3
internal/api/package_delete.go 1
internal/api/presigned_multipart.go 6
internal/api/presigned_uploads.go 17
internal/api/projects.go 4
internal/api/projects_groups.go 1
internal/api/properties.go 1
internal/api/quotas.go 1
internal/api/repo_access.go 2
internal/api/repositories_activity.go 2
internal/api/repositories_catalog_list.go 4
internal/api/repositories_catalog_packages.go 3
internal/api/repositories.go 32
internal/api/repositories_project.go 6
internal/api/sbom.go 8
internal/api/secrets.go 4
internal/api/security_export.go 5
internal/api/security_findings.go 3
internal/api/security_health.go 5
internal/api/server.go 2
internal/api/sso_common.go 7
internal/api/sso_oidc_handlers.go 7
internal/api/sso_saml_handlers.go 8
internal/api/tokens_unified.go 2
internal/api/trash.go 4
internal/api/trash_regen.go 3
internal/api/upload_deb.go 12
internal/api/upload_maven.go 22
internal/api/upload_npm.go 37
internal/api/upload_rpm.go 19
internal/api/vex.go 6
internal/api/vuln_distro.go 1
internal/api/vuln.go 6
internal/api/vuln_overview.go 6
internal/api/webhooks.go 3
internal/auth/bootstrap.go 3
internal/auth/oidc_identity.go 1
internal/auth/permission.go 1
internal/auth/saml.go 1
internal/auth/saml_keypair.go 3
internal/auth/saml_metadata.go 1
internal/auth/sso_keys.go 2
internal/auth/sso_provisioner.go 6
internal/format/apk/http.go 5
internal/format/apk/upload.go 9
internal/format/base/handler.go 1
internal/format/base/serve.go 4
internal/format/cargo/http.go 28
internal/format/conan/checksum.go 1
internal/format/conan/delete.go 2
internal/format/conan/files.go 4
internal/format/conan/http.go 3
internal/format/conda/http.go 17
internal/format/deb/http.go 11
internal/format/docker/catalog.go 2
internal/format/docker/http.go 61
internal/format/filerepo/handler.go 15
internal/format/gomod/http.go 23
internal/format/gomod/repair.go 4
internal/format/helm/http.go 27
internal/format/maven/http.go 11
internal/format/npm/http.go 16
internal/format/nuget/http.go 35
internal/format/pacman/http.go 3
internal/format/pacman/range.go 2
internal/format/pacman/upload.go 12
internal/format/pypi/http.go 29
internal/format/raw/commit.go 2
internal/format/raw/http.go 18
internal/format/rpm/http.go 3
internal/format/rubygems/compact.go 6
internal/format/rubygems/http.go 29
internal/format/terraform/delete.go 7
internal/format/terraform/http.go 1
internal/format/terraform/provider_download.go 4
internal/format/terraform/publish.go 7
internal/format/terraform/registry.go 9
internal/format/terraform/ticket_download.go 3
internal/group/apk.go 1
internal/group/cargo.go 1
internal/group/conan.go 4
internal/group/conda.go 6
internal/group/debrpm.go 10
internal/group/group.go 1
internal/group/helm.go 2
internal/group/hostedwins.go 2
internal/group/ivysbt.go 1
internal/group/maven.go 2
internal/group/npm.go 1
internal/group/nuget.go 7
internal/group/oci.go 2
internal/group/pypi.go 5
internal/group/rubygems.go 5
internal/group/terraform.go 5
internal/mcp/metadata.go 1
internal/mcp/server.go 1
internal/middleware/middleware.go 1
internal/middleware/rbac.go 6
internal/middleware/rbac_mcp.go 4
internal/middleware/rbac_projects.go 3
internal/presign/presign.go 2
internal/proxy/apk.go 3
internal/proxy/cargo.go 8
internal/proxy/conan.go 16
internal/proxy/conan_v1.go 2
internal/proxy/conda.go 6
internal/proxy/gomod.go 1
internal/proxy/gosumdb.go 4
internal/proxy/helm.go 11
internal/proxy/npm.go 4
internal/proxy/nuget.go 13
internal/proxy/oci_auth.go 15
internal/proxy/oci.go 22
internal/proxy/oci_list.go 3
internal/proxy/open.go 1
internal/proxy/proxy.go 29
internal/proxy/pypi.go 14
internal/proxy/rubygems.go 5
internal/proxy/terraform.go 28
internal/repodispatch/dispatch.go 3
internal/search/handler.go 5

gjed added 2 commits October 28, 2026 13:50
…p bridge

With telemetry.otlp.logs on, the application logger is teed with an
otelzap core (go.opentelemetry.io/contrib/bridges/otelzap v0.21.0) on the
application scope, at the logger's level. The configured output is
unchanged.

telemetry.LogFields also returns the context in a zapcore.SkipType field:
no encoder writes it, and the bridge emits the record under it, so the
record carries the request span's trace and span ids as its own. Only the
request log line passes the request context today.

The exporter error handler keeps the logger without the bridge, so export
failures are never queued for export.

Refs: #192
@gjed gjed self-assigned this Oct 28, 2026
@github-actions

Copy link
Copy Markdown

Coverage

Coverage vs main
Go, unit + integration 80.4% ±0.0
Go, unit tests only 66.8% ±0.0
Go, integration tests only 58.2% +0.1
Web, lines 87.7% ±0.0
Web, functions 82.9% ±0.0
Go by area
Area Coverage vs main
cmd/docgen 82.0% ±0.0
cmd/genformats 86.4% ±0.0
cmd/oa 79.7% ±0.0
cmd/resetpw 0.0% ±0.0
cmd/server 70.9% -0.2
internal/ai 87.2% ±0.0
internal/api 73.4% ±0.0
internal/apkkeys 77.1% ±0.0
internal/attest 84.7% ±0.0
internal/audit 92.9% ±0.0
internal/auth 90.5% ±0.0
internal/backup 65.7% ±0.0
internal/bgtask 96.2% ±0.0
internal/branding 93.4% ±0.0
internal/clientsetup 93.1% ±0.0
internal/config 95.6% ±0.0
internal/cron 90.2% ±0.0
internal/crypto 90.7% ±0.0
internal/database 67.9% ±0.0
internal/declarative 75.5% ±0.0
internal/dtrack 85.1% ±0.0
internal/federation 80.9% ±0.0
internal/format 78.1% ±0.0
internal/gpgkeys 87.3% ±0.0
internal/group 89.0% ±0.0
internal/httpcache 100.0% ±0.0
internal/httpx 100.0% ±0.0
internal/importmeta 93.3% ±0.0
internal/iocopy 100.0% ±0.0
internal/license 99.4% ±0.0
internal/licensemeta 94.3% ±0.0
internal/licensepolicy 92.6% ±0.0
internal/mcp 87.1% ±0.0
internal/metrics 96.2% ±0.0
internal/middleware 93.5% ±0.0
internal/netutil 94.0% ±0.0
internal/ocimanifest 100.0% ±0.0
internal/ocipath 100.0% ±0.0
internal/passwd 86.5% ±0.0
internal/pathseg 100.0% ±0.0
internal/pkgdeps 91.9% ±0.0
internal/presign 99.0% ±0.0
internal/promote 86.4% ±0.0
internal/proxy 86.2% ±0.0
internal/pypisimple 97.3% ±0.0
internal/quarantine 100.0% ±0.0
internal/quota 87.8% ±0.0
internal/recovery 85.3% +0.6
internal/replication 76.3% ±0.0
internal/repodispatch 85.1% ±0.0
internal/repotype 95.5% ±0.0
internal/sbom 89.6% ±0.0
internal/scanexport 95.6% ±0.0
internal/search 90.6% ±0.0
internal/secrets 87.7% ±0.0
internal/storage 83.6% ±0.0
internal/telemetry 87.7% +2.0
internal/tiering 81.4% ±0.0
internal/trash 96.7% ±0.0
internal/urlparams 100.0% ±0.0
internal/vuln 88.2% -0.2
internal/webhook 84.7% ±0.0
internal/worker 82.8% -0.1
internal/xzutil 80.0% ±0.0
pkg/apk 96.0% ±0.0
pkg/cargo 95.3% ±0.0
pkg/compactindex 97.6% ±0.0
pkg/conan 99.2% ±0.0
pkg/conda 94.2% ±0.0
pkg/deb 76.1% ±0.0
pkg/delta 71.4% ±0.0
pkg/gpg 86.7% ±0.0
pkg/helm 95.9% ±0.0
pkg/logger 93.8% -2.3
pkg/maven 96.7% ±0.0
pkg/npm 89.4% ±0.0
pkg/nuget 97.6% ±0.0
pkg/pacman 89.8% ±0.0
pkg/rpm 91.8% ±0.0
pkg/rpmsign 90.5% ±0.0
pkg/rubymarshal 86.7% ±0.0
tests/integration 79.2% ±0.0
web 95.5% ±0.0
Web by area (lines)
Area Coverage vs main
src 23.5% ±0.0
src/api 88.2% ±0.0
src/components 85.9% ±0.0
src/composables 91.5% ±0.0
src/i18n 96.5% ±0.0
src/lib 98.6% ±0.0
src/pages 87.8% ±0.0
src/pwa 98.8% ±0.0
src/router 99.3% ±0.0
src/stores 98.9% ±0.0

Full report (HTML, merged profile) in the CI run artifacts

@M0Rf30 M0Rf30 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks, this is in good shape. Reviewed the diff, ran go test ./internal/telemetry ./pkg/logger ./internal/middleware; integration passed in CI.

Checked specifically: no ForceFlush reachable (otelzap Sync() is a no-op, only Shutdown flushes, so the #304 slot note doesn't apply); zapcore.NewTee writes each entry once per core and stdout is untouched with OTLP logs off; the error handler keeps the pre-tee logger, so export failures don't loop; trace/span ids on records match the server span in the collector test; zero allocations with the feature off; telemetry shuts down last, so drain-time logs are exported.

Non-blocking:

  1. Every log field now leaves the host: remote_addr, user/user_id, username, search query, upstream url, error strings that can embed URLs. I found no token/password/Authorization fields. Please say in docs/operations/monitoring.md that OTLP logs carry client IPs and user identifiers, so the collector pipeline must be treated accordingly.
  2. Add a test that an error field ends up as exception.message on the exported record (the docs claim it).
  3. Document that a .Named() logger creates a new scope, and with it a new value of the drop counter's scope label.
  4. Records emitted after Shutdown are discarded by the SDK but count as drops (in-flight slots not released). Negligible today; only matters if something logs after shutdown.

@gjed gjed left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copilot review overview

reviewer is the PR author — review event submitted as COMMENT.

Review effort: Standard
Findings: 1 Medium severity · 3 Low severity

Open (4)
What changed in this PR

Application logs go over OTLP through the otelzap bridge on the log provider telemetry.Setup already installs, when telemetry.otlp.logs is on. The stdout/file output does not change.

Changes:

  • logger.Tee tees the application logger with the otelzap core, filtered at the logger's level; cmd/server swaps it in right after telemetry.Setup.
  • telemetry.LogFields(ctx) also returns ctx in a zapcore.SkipType field, so encoders write nothing extra and the bridge emits the record under the request span's real trace and span ids.
  • Severity, service.* resource attributes and drop counting come from the bridge, the provider and the existing counting processor; the exporter error handler keeps the un-teed logger.
  • Docs and example files updated; the config reference is regenerated.
File Description
.env.example OTEL_LOGS_EXPORTER comment: no longer reserved.
cmd/server/app_startup.go setupTelemetry tees the application logger with the OTLP bridge when telemetry.otlp.logs is on.
docker/.env.example Logs line reworded; only audit stays reserved.
docs/operations/monitoring.md Documents log records over OTLP: scope, record fields, correlation, known limits.
docs/reference/config.md Regenerated telemetry.otlp.logs row.
go.mod Adds go.opentelemetry.io/contrib/bridges/otelzap v0.21.0.
go.sum Checksums for otelzap and its logtest test dependency.
internal/telemetry/config.go Logs field comment: records are now written.
internal/telemetry/logfields.go LogFields also returns ctx in a zapcore.SkipType field; new LogCore() returns the otelzap core on the application scope.
internal/telemetry/logfields_test.go Unit test: record ids, severity and scope; stdout line keeps exactly the old fields.
internal/telemetry/telemetry_test.go TestLogFields expects the extra ctx field.
openartifact.example.yaml logs comment reworded.
pkg/logger/logger.go New Logger.Tee(core): writes to the output and to core, filtered at the logger's level.
pkg/logger/logger_test.go Unit test for Tee: both outputs, level cut, original logger untouched.
tests/integration/otlp_logs_test.go Integration test: a request's records reach a real collector with the server span's trace and span ids, INFO severity and the provider's service.name.

Comment thread docs/operations/monitoring.md Resolved
Comment thread docs/operations/monitoring.md Resolved
Comment thread docs/operations/monitoring.md Resolved
Comment thread cmd/server/app_startup.go Resolved
@M0Rf30
M0Rf30 merged commit 5b5e0fe into main Oct 28, 2026
20 checks passed
@M0Rf30
M0Rf30 deleted the feat/otlp-logs-bridge branch October 28, 2026 15:38
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.

Telemetry: export application logs over OTLP

2 participants