Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Logger support in otelhttp #5363

Closed
wants to merge 2 commits into from

Conversation

seanpburke
Copy link

@seanpburke seanpburke commented Apr 5, 2024

Problem Statement

The otelhttp middleware is an ideal place to log HTTP transactions, because important data are available, such as:

  • HTTP status code
  • Elapsed Time
  • Bytes read and written

Now that the minimal Go version is 1.21, in which the package log/slog is part of the standard library,
a standard API is available to generate structured log records.

OpenTelemetry loggers can be used with the log/slog API via go.opentelemetry.io/contrib/bridges/otelslog.

Proposed Solution

The middleware can optionally be configured with a *slog.Logger:

    mware := otelhttp.NewMiddleware(operation, otelhttp.WithLogger(logger))

If a Logger has been configured, a log record will be emitted with the same attributes as the Span:

{
  "time": "2024-04-05T15:42:16.926178547-07:00",
  "level": "INFO",
  "msg": "operation",
  "http.method": "GET",
  "http.scheme": "http",
  "net.host.name": "tonio.attlocal.net",
  "net.host.port": 8080,
  "net.protocol.name": "http",
  "net.protocol.version": "1.1",
  "http.status_code": 200, 
  "http.wrote_bytes": 3954,
  "http.server.duration": 4.426442,
}

@seanpburke seanpburke requested review from Aneurysm9, dmathieu and a team as code owners April 5, 2024 23:37
Copy link

linux-foundation-easycla bot commented Apr 5, 2024

CLA Signed


The committers listed above are authorized under a signed CLA.

Copy link
Contributor

@MrAlias MrAlias left a comment

Choose a reason for hiding this comment

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

Please see my response to your issue: #5362 (comment)

We do not plan to accept these changes without broader OpenTelemetry buy in and standardization.

@seanpburke seanpburke closed this Apr 5, 2024
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.

None yet

2 participants