Skip to content

Conversation

felix-hilden
Copy link

@felix-hilden felix-hilden commented Sep 20, 2025

Fixes #7261

Hi @mholt, if I may ping you, thanks for labeling the associated issue! I decided to try to contribute a fix, as the scope is quite well defined.

First, I think my initial suggestion in the ticket of using a flat directive would probably
be improved by using a map instead, more consistent to what Caddyfile already does:

tracing {
  span my-span-name
  span_attributes {
    attr1 value1
    attr2 {placeholder}
  }
}

I'm disclosing that I have used Claude to generate most of the code in this PR as this is my first time touching Go in general, although naturally I reviewed the output and tried to understand it. So if holding my hand through the MR is too much, feel free to discard it altogether in favor of a better solution!

If not, there are a couple of things I wanted to ask about. I think given the tests, is pretty already in a reasonable place. Building from that, on a practical level if you have quick pointers:

  • Is the use of placeholders implemented and tested reasonably?
  • Do we need to do anything special to support JSON configuration? I know we have some JSON processing in the module already in the struct, but I'm asking just in case.
  • For documentation, I created WIP: Add span attributes to tracing documentation website#496. Do we need anything more, e.g. in code?

Many thanks! I'm very excited to try out Caddy for real and hopefully switch to it for good.

@CLAassistant
Copy link

CLAassistant commented Sep 20, 2025

CLA assistant check
All committers have signed the CLA.


````bash
$ go test ./...
$ go test ./modules/caddyhttp/tracing/
Copy link
Author

Choose a reason for hiding this comment

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

Also I thought for newbies like me, if you want to attract them 😅 this is a helpful first pointer after the build.

@mholt
Copy link
Member

mholt commented Sep 24, 2025

Thanks for the contribution! I'll ask if @hairyhenderson, who I know is very busy, might have a chance to look this over, since I don't know much about the metrics/tracing stuff.

@felix-hilden
Copy link
Author

Thank you! That would be much appreciated. But also I think the tracing part is the simple one. I believe based on the test that the span attributes are already recorded correctly. But the hard part is the replacements. I don't think I found a nice example of how response placeholders are generated and used. I pushed a test expecting a default span attr from OTEL, but you can see it fail there. Additionally, I couldn't really use the other response placeholders out of the box either. So I wonder if I'm doing something wrong either in setting up the test to be realistic, or in the middleware code to make them unavailable.

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.

Allow setting span attributes in opentelemetry tracing
3 participants