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

new option ot_span_decorator #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

trashhalo
Copy link

use to inspect response and expand attributes.

Anthropic returns usage data in headers in the json response. I wanted that data on the http span. I dont think this a unique ask as rate limits are often represented in headers.

# example from our codebase for anthropic
 ot_span_decorator = fn resp ->
      resp.headers
      |> Enum.filter(fn {k, _v} -> String.starts_with?(k, "anthropic-") end)
      |> Enum.map(fn {k, v} -> {String.replace(k, "-", "."), v} end)
      |> OpenTelemetry.Tracer.set_attributes()

      case resp.body |> Jason.decode!() |> Map.get("usage") do
        nil ->
          :ok

        usage ->
          Enum.each(usage, fn {k, v} ->
            OpenTelemetry.Tracer.set_attribute("anthropic.usage.#{k}", v)
          end)
      end
    end

Then pass to requests at the same level you currently pass ot_attributes

@trashhalo trashhalo requested a review from a team as a code owner December 18, 2024 01:48
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.

1 participant