Repository navigation
feat(telemetry): export application logs over OTLP through the otelzap bridge - #321
Conversation
…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
Coverage
Go by area
Web by area (lines)
|
M0Rf30
left a comment
There was a problem hiding this comment.
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:
- Every log field now leaves the host:
remote_addr,user/user_id,username, searchquery, upstreamurl, error strings that can embed URLs. I found no token/password/Authorization fields. Please say indocs/operations/monitoring.mdthat OTLP logs carry client IPs and user identifiers, so the collector pipeline must be treated accordingly. - Add a test that an
errorfield ends up asexception.messageon the exported record (the docs claim it). - Document that a
.Named()logger creates a new scope, and with it a new value of the drop counter'sscopelabel. - Records emitted after
Shutdownare discarded by the SDK but count as drops (in-flight slots not released). Negligible today; only matters if something logs after shutdown.
gjed
left a comment
There was a problem hiding this comment.
Copilot review overview
reviewer is the PR author — review event submitted as COMMENT.
Review effort: Standard
Findings: 1
Open (4)
add anUnreleasedupgrade note:logsstarts exporting every log line on upgrade. · New "every line the server logs" is not exact: the startup banner and the unencrypted-secrets warning… · New should log records carrypath,remote_addrand the error text when the trace attributes carry… · New is theotlp.Enabled && otlp.Logsgate and thea.log = logswap covered by a test? · New
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.Teetees the application logger with the otelzap core, filtered at the logger's level;cmd/serverswaps it in right aftertelemetry.Setup.telemetry.LogFields(ctx)also returns ctx in azapcore.SkipTypefield, 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. |


Closes #192.
Application logs go over OTLP through
go.opentelemetry.io/contrib/bridges/otelzap(v0.21.0, the same contrib release as the pinnedbridges/prometheusv0.72.0), on the log providertelemetry.Setupalready installs (#224), only whentelemetry.otlp.logs/OTEL_LOGS_EXPORTER=otlpis on.What changes
logger.Teetees the application logger with the otelzap core on the application scopegithub.com/openartifact/openartifact, filtered at the logger's level (no debug records atinfo).cmd/serverswaps in the teed logger right aftertelemetry.Setup. The stdout/file output does not change.telemetry.LogFields(ctx)now also returns ctx in azapcore.SkipTypefield. Encoders never write a skip field, so stdout lines are byte-identical; otelzap v0.21.0 takes anycontext.Contextfield value as the emit context, so the record carries the request span's real TraceID/SpanID, not onlytrace_id/span_idattributes.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.docs/operations/monitoring.md, the config reference (regenerated) and the example files.docker/otel-collector.yamlalready has alogspipeline (otlp→memory_limiter, batch→otlp_http), so it is unchanged.Tests
tests/integration:TestOTLPRequestLogsCarryTheRequestSpanserves a request throughtelemetry.HTTPMiddleware,TracingMiddlewareandLoggingMiddlewarewith a handler log line, against a real collector (otelcoltest), and asserts that each record'straceId/spanIdequals the exported server span, with INFO severity and the provider'sservice.name. With the ctx field removed fromLogFieldsit fails (record ids /, want the request span …).TestLogCoreEmitsUnderTheLoggedSpan(record ids, severity and scope; stdout line has exactly the old fields),TestTeeWritesBothAtTheLoggerLevel.Local:
make lint(only the existingpkg/rpm/dependencies.go:72nolintlint, also on main),make test,make test-integration(DB/S3-gated tests skipped locally),make deadcode,make docs-gen,make docs-check.Known limits
HTTP requestline is written with the request context. Every other request-path log call has no ctx: no trace/span id over OTLP (and notrace_idon 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 recoveredwould gain nothing from ctx:RecoveryMiddlewareis mounted outsidetelemetry.HTTPMiddleware, so its request has no span.trace_id/span_idas 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
internal/api/admin_ai.gointernal/api/admin_apk_key.gointernal/api/admin_audit.gointernal/api/admin_gpg.gointernal/api/admin_groups.gointernal/api/admin_recovery.gointernal/api/admin_replication.gointernal/api/admin_sso.gointernal/api/admin_storage.gointernal/api/admin_storage_primary.gointernal/api/admin_tiering.gointernal/api/admin_tokens.gointernal/api/admin_users.gointernal/api/ai.gointernal/api/artifact_detail.gointernal/api/attestation_attach.gointernal/api/attestation.gointernal/api/audit_export.gointernal/api/audit_subjects.gointernal/api/auth_handlers.gointernal/api/backup.gointernal/api/branding.gointernal/api/bundles_authz.gointernal/api/bundles.gointernal/api/bundles_promote.gointernal/api/bundles_signing.gointernal/api/cleanup.gointernal/api/delta.gointernal/api/dependency_track.gointernal/api/docker_gc.gointernal/api/license_artifact.gointernal/api/maven_parent_license.gointernal/api/package_delete.gointernal/api/presigned_multipart.gointernal/api/presigned_uploads.gointernal/api/projects.gointernal/api/projects_groups.gointernal/api/properties.gointernal/api/quotas.gointernal/api/repo_access.gointernal/api/repositories_activity.gointernal/api/repositories_catalog_list.gointernal/api/repositories_catalog_packages.gointernal/api/repositories.gointernal/api/repositories_project.gointernal/api/sbom.gointernal/api/secrets.gointernal/api/security_export.gointernal/api/security_findings.gointernal/api/security_health.gointernal/api/server.gointernal/api/sso_common.gointernal/api/sso_oidc_handlers.gointernal/api/sso_saml_handlers.gointernal/api/tokens_unified.gointernal/api/trash.gointernal/api/trash_regen.gointernal/api/upload_deb.gointernal/api/upload_maven.gointernal/api/upload_npm.gointernal/api/upload_rpm.gointernal/api/vex.gointernal/api/vuln_distro.gointernal/api/vuln.gointernal/api/vuln_overview.gointernal/api/webhooks.gointernal/auth/bootstrap.gointernal/auth/oidc_identity.gointernal/auth/permission.gointernal/auth/saml.gointernal/auth/saml_keypair.gointernal/auth/saml_metadata.gointernal/auth/sso_keys.gointernal/auth/sso_provisioner.gointernal/format/apk/http.gointernal/format/apk/upload.gointernal/format/base/handler.gointernal/format/base/serve.gointernal/format/cargo/http.gointernal/format/conan/checksum.gointernal/format/conan/delete.gointernal/format/conan/files.gointernal/format/conan/http.gointernal/format/conda/http.gointernal/format/deb/http.gointernal/format/docker/catalog.gointernal/format/docker/http.gointernal/format/filerepo/handler.gointernal/format/gomod/http.gointernal/format/gomod/repair.gointernal/format/helm/http.gointernal/format/maven/http.gointernal/format/npm/http.gointernal/format/nuget/http.gointernal/format/pacman/http.gointernal/format/pacman/range.gointernal/format/pacman/upload.gointernal/format/pypi/http.gointernal/format/raw/commit.gointernal/format/raw/http.gointernal/format/rpm/http.gointernal/format/rubygems/compact.gointernal/format/rubygems/http.gointernal/format/terraform/delete.gointernal/format/terraform/http.gointernal/format/terraform/provider_download.gointernal/format/terraform/publish.gointernal/format/terraform/registry.gointernal/format/terraform/ticket_download.gointernal/group/apk.gointernal/group/cargo.gointernal/group/conan.gointernal/group/conda.gointernal/group/debrpm.gointernal/group/group.gointernal/group/helm.gointernal/group/hostedwins.gointernal/group/ivysbt.gointernal/group/maven.gointernal/group/npm.gointernal/group/nuget.gointernal/group/oci.gointernal/group/pypi.gointernal/group/rubygems.gointernal/group/terraform.gointernal/mcp/metadata.gointernal/mcp/server.gointernal/middleware/middleware.gointernal/middleware/rbac.gointernal/middleware/rbac_mcp.gointernal/middleware/rbac_projects.gointernal/presign/presign.gointernal/proxy/apk.gointernal/proxy/cargo.gointernal/proxy/conan.gointernal/proxy/conan_v1.gointernal/proxy/conda.gointernal/proxy/gomod.gointernal/proxy/gosumdb.gointernal/proxy/helm.gointernal/proxy/npm.gointernal/proxy/nuget.gointernal/proxy/oci_auth.gointernal/proxy/oci.gointernal/proxy/oci_list.gointernal/proxy/open.gointernal/proxy/proxy.gointernal/proxy/pypi.gointernal/proxy/rubygems.gointernal/proxy/terraform.gointernal/repodispatch/dispatch.gointernal/search/handler.go