Skip to content

Otel4s tracing middleware#768

Merged
cquiroz merged 15 commits intomainfrom
otel4s-tracieng
Apr 21, 2026
Merged

Otel4s tracing middleware#768
cquiroz merged 15 commits intomainfrom
otel4s-tracieng

Conversation

@cquiroz
Copy link
Copy Markdown
Collaborator

@cquiroz cquiroz commented Apr 20, 2026

A more or less one-to-one conversion of the NatchezMiddleware to Otel4sMiddleware. Also includes propagating W3C trace context to connect client spans to server spans as suggested at https://ochenashko.com/practical-observability-distributed-tracing/#6-cross-service-propagation

F: MonadThrow[F],
backend: Http4sHttpBackend[F],
logger: Logger[F]
def of[F[_]: {MonadThrow as F, Http4sHttpBackend as B, Logger as L}, S](
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.

F and L are pretty standard notation. But B isn't and backend is much more descriptive as a var name.

mergedExt = Some(traceExt).filterNot(_.isEmpty)
result <- poll(
wrapped
.subscribeInternal[D](document, operationName, variables, mergedExt)
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.

Not much, but we are dupicating some logic here. Maybe we can invoke requestInternal and pass extensions through it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, there is no harm in passing them on the requests, though they are wasted as they are not read since we have the traceparent on the headers. otoh we may pass more extensions in the future?

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.

This is the streaming client. The requests go over web sockets so the trace info is on the extensions since there are no headers.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added the suggested fix

document: GraphQLQuery,
operationName: Option[String] = none,
variables: Option[JsonObject] = none,
extensions: Option[JsonObject] = none,
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.

It would be nice to support extensions here, but this is another concern for another PR.

Copy link
Copy Markdown
Collaborator

@rpiaggio rpiaggio left a comment

Choose a reason for hiding this comment

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

LGTM

@cquiroz cquiroz merged commit a24c807 into main Apr 21, 2026
12 checks passed
@cquiroz cquiroz deleted the otel4s-tracieng branch April 21, 2026 20:43
@mergify mergify Bot added the otel4s label Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants