Skip to content

Implement Cohere instrumentation#3081

Closed
lzchen wants to merge 29 commits intoopen-telemetry:mainfrom
lzchen:cohere
Closed

Implement Cohere instrumentation#3081
lzchen wants to merge 29 commits intoopen-telemetry:mainfrom
lzchen:cohere

Conversation

@lzchen
Copy link
Copy Markdown
Contributor

@lzchen lzchen commented Dec 9, 2024

Part of #3050

TODO:

Add tests
Support streaming

lzchen added 26 commits August 29, 2024 11:33
}
response_format = kwargs.get("response_format")
if response_format:
# TODO: Add to sem conv
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we make the openai generic instead?

Copy link
Copy Markdown
Contributor

@codefromthecrypt codefromthecrypt Dec 13, 2024

Choose a reason for hiding this comment

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

so you mean remove the openai one and make a generic one for this entry: https://github.com/open-telemetry/semantic-conventions/blob/abd92c153b627efd3222e6b46828c5e94bf1b2cd/model/gen-ai/spans.yaml#L88

I think it can make sense, and in any case we can open an issue any cohere specific attributes and add that into the TODO comment. That issue could be closed either by normalizing things from openai, cohere specific adds, or a combo.

@karthikscale3 you happen to know how many other LLM providers have a concept of response_format?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@lmolkova Is it possible to have a generic attribute but have each implementation (openai, cohere) have their own list of possible values?

"stop_sequences"
),
GenAIAttributes.GEN_AI_REQUEST_TEMPERATURE: kwargs.get("temperature"),
# TODO: Add to sem conv
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

I'd merge it with gen_ai.openai.request.seed into gen_ai.request.seed

if getattr(result.usage, "tokens"):
span.set_attribute(
GenAIAttributes.GEN_AI_USAGE_INPUT_TOKENS,
result.usage.tokens.input_tokens,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

PTAL at the https://github.com/open-telemetry/semantic-conventions/issues/1279

Cohere reports billed tokens in addition to input/output

image

https://docs.cohere.com/v2/reference/chat#response.body.usage

I'm not sure what's the difference and if we need to report one or another (or maybe both?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@lzchen is it alright if I split this into a separate PR? I'd like to use it in the vertex instrumentation too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

#3188 running into the same CI failures


def get_span_name(span_attributes):
name = span_attributes.get(GenAIAttributes.GEN_AI_OPERATION_NAME, "")
model = span_attributes.get(GenAIAttributes.GEN_AI_REQUEST_MODEL, "")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

model might not be available in some cases, we should report "f{name}"

span.set_attribute(
ErrorAttributes.ERROR_TYPE, type(error).__qualname__
)
span.end()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is span.end() needed?

trace.get_tracer_provider().add_span_processor(
BatchSpanProcessor(ConsoleSpanExporter())
)
tracer = trace.get_tracer(__name__)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we setup logs/events and mention how to turn on content?

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Mar 11, 2026
@github-actions
Copy link
Copy Markdown

This PR has been closed due to inactivity. Please reopen if you would like to continue working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants