Skip to content

Commit

Permalink
chore(openai): add model tag for openai metrics for consistency wit…
Browse files Browse the repository at this point in the history
…h openai saas integration [backport 2.11] (#10382)

Backport 07ecb27 from #10282 to 2.11.

Metrics from the OpenAI SaaS integration `(openai.api.usage...)` have a
`model` tag. We should also tag metrics from OpenAI APM Integration with
`model` for convenience (for example if customers want to use both
`openai.api.usage...` metrics and `openai.ratelimit...` metrics in the
same dashboard).

Addresses #10185

## Checklist
- [x] PR author has checked that all the criteria below are met
- The PR description includes an overview of the change
- The PR description articulates the motivation for the change
- The change includes tests OR the PR description describes a testing
strategy
- The PR description notes risks associated with the change, if any
- Newly-added code is easy to change
- The change follows the [library release note
guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html)
- The change includes or references documentation updates if necessary
- Backport labels are set (if
[applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting))

## Reviewer Checklist
- [x] Reviewer has checked that all the criteria below are met 
- Title is accurate
- All changes are related to the pull request's stated goal
- Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes
- Testing strategy adequately addresses listed risks
- Newly-added code is easy to change
- Release note makes sense to a user of the library
- If necessary, author has acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment
- Backport labels are set in a manner that is consistent with the
[release branch maintenance
policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)

Co-authored-by: lievan <[email protected]>
Co-authored-by: Yun Kim <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent b95a737 commit 26e44e4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ddtrace/llmobs/_integrations/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,13 @@ def _logs_tags(cls, span: Span) -> str:

@classmethod
def _metrics_tags(cls, span: Span) -> List[str]:
model_name = span.get_tag("openai.request.model") or ""
tags = [
"version:%s" % (config.version or ""),
"env:%s" % (config.env or ""),
"service:%s" % (span.service or ""),
"openai.request.model:%s" % (span.get_tag("openai.request.model") or ""),
"openai.request.model:%s" % model_name,
"model:%s" % model_name,
"openai.request.endpoint:%s" % (span.get_tag("openai.request.endpoint") or ""),
"openai.request.method:%s" % (span.get_tag("openai.request.method") or ""),
"openai.organization.id:%s" % (span.get_tag("openai.organization.id") or ""),
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/openai-model-tag-2482b3d5b2905db9.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
features:
- |
openai: This introduces 'model' tag for openai integration metrics for consistency with the OpenAI SaaS Integration. It has the same value as `openai.request.model`.
7 changes: 7 additions & 0 deletions tests/contrib/openai/test_openai_v0.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_completion(
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -220,6 +221,7 @@ async def test_acompletion(
"env:",
"service:",
"openai.request.model:curie",
"model:curie",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -321,6 +323,7 @@ def test_global_tags(openai_vcr, ddtrace_config_openai, openai, mock_metrics, mo
"env:staging",
"version:1234",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.name:datadog-4",
Expand Down Expand Up @@ -1285,6 +1288,7 @@ def test_completion_stream(openai, openai_vcr, mock_metrics, mock_tracer):
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1325,6 +1329,7 @@ async def test_completion_async_stream(openai, openai_vcr, mock_metrics, mock_tr
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1372,6 +1377,7 @@ def test_chat_completion_stream(openai, openai_vcr, mock_metrics, snapshot_trace
"env:",
"service:",
"openai.request.model:gpt-3.5-turbo",
"model:gpt-3.5-turbo",
"openai.request.endpoint:/v1/chat/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1422,6 +1428,7 @@ async def test_chat_completion_async_stream(openai, openai_vcr, mock_metrics, sn
"env:",
"service:",
"openai.request.model:gpt-3.5-turbo",
"model:gpt-3.5-turbo",
"openai.request.endpoint:/v1/chat/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down
9 changes: 9 additions & 0 deletions tests/contrib/openai/test_openai_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def test_completion(
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -237,6 +238,7 @@ async def test_acompletion(
"env:",
"service:",
"openai.request.model:curie",
"model:curie",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -344,6 +346,7 @@ def test_global_tags(openai_vcr, ddtrace_config_openai, openai, mock_metrics, mo
"env:staging",
"version:1234",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.name:datadog-4",
Expand Down Expand Up @@ -941,6 +944,7 @@ def test_completion_stream(openai, openai_vcr, mock_metrics, mock_tracer):
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -979,6 +983,7 @@ async def test_completion_async_stream(openai, openai_vcr, mock_metrics, mock_tr
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1021,6 +1026,7 @@ def test_completion_stream_context_manager(openai, openai_vcr, mock_metrics, moc
"env:",
"service:",
"openai.request.model:ada",
"model:ada",
"openai.request.endpoint:/v1/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1067,6 +1073,7 @@ def test_chat_completion_stream(openai, openai_vcr, mock_metrics, snapshot_trace
"env:",
"service:",
"openai.request.model:gpt-3.5-turbo",
"model:gpt-3.5-turbo",
"openai.request.endpoint:/v1/chat/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1115,6 +1122,7 @@ async def test_chat_completion_async_stream(openai, openai_vcr, mock_metrics, sn
"env:",
"service:",
"openai.request.model:gpt-3.5-turbo",
"model:gpt-3.5-turbo",
"openai.request.endpoint:/v1/chat/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down Expand Up @@ -1170,6 +1178,7 @@ async def test_chat_completion_async_stream_context_manager(openai, openai_vcr,
"env:",
"service:",
"openai.request.model:gpt-3.5-turbo",
"model:gpt-3.5-turbo",
"openai.request.endpoint:/v1/chat/completions",
"openai.request.method:POST",
"openai.organization.id:",
Expand Down

0 comments on commit 26e44e4

Please sign in to comment.