Skip to content

Commit 43750c0

Browse files
Merge branch 'main' into fix/1477
2 parents 113222a + b76119b commit 43750c0

File tree

40 files changed

+8166
-256
lines changed

40 files changed

+8166
-256
lines changed

.github/workflows/fossa.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: FOSSA scanning
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
fossa:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
16+
17+
- uses: fossas/fossa-action@93a52ecf7c3ac7eb40f5de77fd69b1a19524de94 # v1.5.0
18+
with:
19+
api-key: ${{secrets.FOSSA_API_KEY}}
20+
team: OpenTelemetry

.github/workflows/package-prepare-patch-release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ on:
99
- opentelemetry-resource-detector-azure
1010
- opentelemetry-sdk-extension-aws
1111
- opentelemetry-instrumentation-openai-v2
12+
- opentelemetry-instrumentation-vertexai
1213
description: 'Package to be released'
1314
required: true
15+
run-name: "[Package][${{ inputs.package }}] Prepare patch release"
16+
1417
jobs:
1518
prepare-patch-release:
1619
runs-on: ubuntu-latest

.github/workflows/package-prepare-release.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ on:
99
- opentelemetry-resource-detector-azure
1010
- opentelemetry-sdk-extension-aws
1111
- opentelemetry-instrumentation-openai-v2
12+
- opentelemetry-instrumentation-vertexai
1213
description: 'Package to be released'
1314
required: true
1415

16+
run-name: "[Package][${{ inputs.package }}] Prepare release"
1517
jobs:
1618
prereqs:
1719
runs-on: ubuntu-latest

.github/workflows/package-release.yml

+2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ on:
99
- opentelemetry-resource-detector-azure
1010
- opentelemetry-sdk-extension-aws
1111
- opentelemetry-instrumentation-openai-v2
12+
- opentelemetry-instrumentation-vertexai
1213
description: 'Package to be released'
1314
required: true
15+
run-name: "[Package][${{ inputs.package }}] Release"
1416
jobs:
1517
release:
1618
runs-on: ubuntu-latest

.pre-commit-config.yaml

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
repos:
2-
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
# Ruff version.
4-
rev: v0.6.9
5-
hooks:
6-
# Run the linter.
7-
- id: ruff
8-
args: ["--fix", "--show-fixes"]
9-
# Run the formatter.
10-
- id: ruff-format
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.6.9
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: ["--fix", "--show-fixes"]
9+
# Run the formatter.
10+
- id: ruff-format
11+
- repo: https://github.com/astral-sh/uv-pre-commit
12+
# uv version.
13+
rev: 0.6.0
14+
hooks:
15+
- id: uv-lock

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Added
1515

16+
- `opentelemetry-instrumentation-system-metrics` Add `process` metrics and deprecated `process.runtime` prefixed ones
17+
([#3250](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3250))
1618
- `opentelemetry-instrumentation-botocore` Add support for GenAI user events and lazy initialize tracer
1719
([#3258](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3258))
1820
- `opentelemetry-instrumentation-botocore` Add support for GenAI system events
1921
([#3266](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3266))
22+
- `opentelemetry-instrumentation-botocore` Add support for GenAI choice events
23+
([#3275](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3275))
24+
- `opentelemetry-instrumentation` make it simpler to initialize auto-instrumentation programmatically
25+
([#3273](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3273))
2026

2127
### Fixed
2228

CONTRIBUTING.md

+39-17
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,31 @@ Please also read the [OpenTelemetry Contributor Guide](https://github.com/open-t
1919

2020
## Index
2121

22-
* [Find a Buddy and get Started Quickly](#find-a-buddy-and-get-started-quickly)
23-
* [Development](#development)
24-
* [Troubleshooting](#troubleshooting)
25-
* [Benchmarks](#benchmarks)
26-
* [Pull requests](#pull-requests)
27-
* [How to Send Pull Requests](#how-to-send-pull-requests)
28-
* [How to Receive Comments](#how-to-receive-comments)
29-
* [How to Get PRs Reviewed](#how-to-get-prs-reviewed)
30-
* [How to Get PRs Merged](#how-to-get-prs-merged)
31-
* [Design Choices](#design-choices)
32-
* [Focus on Capabilities, Not Structure Compliance](#focus-on-capabilities-not-structure-compliance)
33-
* [Running Tests Locally](#running-tests-locally)
34-
* [Testing against a different Core repo branch/commit](#testing-against-a-different-core-repo-branchcommit)
35-
* [Style Guide](#style-guide)
36-
* [Guideline for instrumentations](#guideline-for-instrumentations)
37-
* [Guideline for GenAI instrumentations](#guideline-for-genai-instrumentations)
38-
* [Expectations from contributors](#expectations-from-contributors)
22+
- [Contributing to opentelemetry-python-contrib](#contributing-to-opentelemetry-python-contrib)
23+
- [Index](#index)
24+
- [Find a Buddy and get Started Quickly](#find-a-buddy-and-get-started-quickly)
25+
- [Development](#development)
26+
- [Virtual Environment](#virtual-environment)
27+
- [Troubleshooting](#troubleshooting)
28+
- [Benchmarks](#benchmarks)
29+
- [Pull Requests](#pull-requests)
30+
- [How to Send Pull Requests](#how-to-send-pull-requests)
31+
- [How to Receive Comments](#how-to-receive-comments)
32+
- [How to Get PRs Reviewed](#how-to-get-prs-reviewed)
33+
- [How to Get PRs Merged](#how-to-get-prs-merged)
34+
- [Design Choices](#design-choices)
35+
- [Focus on Capabilities, Not Structure Compliance](#focus-on-capabilities-not-structure-compliance)
36+
- [Running Tests Locally](#running-tests-locally)
37+
- [Testing against a different Core repo branch/commit](#testing-against-a-different-core-repo-branchcommit)
38+
- [Style Guide](#style-guide)
39+
- [Guideline for instrumentations](#guideline-for-instrumentations)
40+
- [Update supported instrumentation package versions](#update-supported-instrumentation-package-versions)
41+
- [Guideline for GenAI instrumentations](#guideline-for-genai-instrumentations)
42+
- [Get Involved](#get-involved)
43+
- [Expectations from contributors](#expectations-from-contributors)
44+
- [Updating supported Python versions](#updating-supported-python-versions)
45+
- [Bumping the Python baseline](#bumping-the-python-baseline)
46+
- [Adding support for a new Python release](#adding-support-for-a-new-python-release)
3947

4048
## Find a Buddy and get Started Quickly
4149

@@ -93,6 +101,20 @@ See
93101
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/tox.ini)
94102
for more detail on available tox commands.
95103

104+
### Virtual Environment
105+
106+
You can also create a single virtual environment to make it easier to run local tests.
107+
108+
For that, you'll need to install [`uv`](https://docs.astral.sh/uv/getting-started/installation/).
109+
110+
After installing `uv`, you can run the following command:
111+
112+
```sh
113+
uv sync
114+
```
115+
116+
This will create a virtual environment in the `.venv` directory and install all the necessary dependencies.
117+
96118
### Troubleshooting
97119

98120
Some packages may require additional system-wide dependencies to be installed. For example, you may need to install `libpq-dev` to run the postgresql client libraries instrumentation tests or `libsnappy-dev` to run the prometheus exporter tests. If you encounter a build error, please check the installation instructions for the package you are trying to run tests for.

RELEASING.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
> - opentelemetry-resource-detector-azure
2222
> - opentelemetry-sdk-extension-aws
2323
> - opentelemetry-instrumentation-openai-v2
24+
> - opentelemetry-instrumentation-vertexai
2425
>
2526
> These libraries are also excluded from the general release.
2627

instrumentation-genai/opentelemetry-instrumentation-openai-v2/examples/manual/README.rst

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ your OpenAI requests.
1111

1212
Note: `.env <.env>`_ file configures additional environment variables:
1313

14-
- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures
15-
OpenAI instrumentation to capture prompt and completion contents on
16-
events.
14+
- ``OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true`` configures OpenAI instrumentation to capture prompt and completion contents on events.
1715

1816
Setup
1917
-----
2018

21-
Minimally, update the `.env <.env>`_ file with your "OPENAI_API_KEY". An
19+
Minimally, update the `.env <.env>`_ file with your ``OPENAI_API_KEY``. An
2220
OTLP compatible endpoint should be listening for traces and logs on
23-
http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.
21+
http://localhost:4317. If not, update ``OTEL_EXPORTER_OTLP_ENDPOINT`` as well.
2422

2523
Next, set up a virtual environment like this:
2624

instrumentation-genai/opentelemetry-instrumentation-openai-v2/examples/zero-code/README.rst

+5-8
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ your OpenAI requests.
1212

1313
Note: `.env <.env>`_ file configures additional environment variables:
1414

15-
- `OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true` configures
16-
OpenTelemetry SDK to export logs and events.
17-
- `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true` configures
18-
OpenAI instrumentation to capture prompt and completion contents on
19-
events.
20-
- `OTEL_LOGS_EXPORTER=otlp` to specify exporter type.
15+
- ``OTEL_PYTHON_LOGGING_AUTO_INSTRUMENTATION_ENABLED=true`` configures OpenTelemetry SDK to export logs and events.
16+
- ``OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true`` configures OpenAI instrumentation to capture prompt and completion contents on events.
17+
- ``OTEL_LOGS_EXPORTER=otlp`` to specify exporter type.
2118

2219
Setup
2320
-----
2421

25-
Minimally, update the `.env <.env>`_ file with your "OPENAI_API_KEY". An
22+
Minimally, update the `.env <.env>`_ file with your ``OPENAI_API_KEY``. An
2623
OTLP compatible endpoint should be listening for traces and logs on
27-
http://localhost:4317. If not, update "OTEL_EXPORTER_OTLP_ENDPOINT" as well.
24+
http://localhost:4317. If not, update ``OTEL_EXPORTER_OTLP_ENDPOINT`` as well.
2825

2926
Next, set up a virtual environment like this:
3027

instrumentation-genai/opentelemetry-instrumentation-vertexai/CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## Version 2.0b0 (2025-02-21)
11+
1012
- Added Vertex AI spans for request parameters
1113
([#3192](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3192))
1214
- Initial VertexAI instrumentation
@@ -15,7 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1517
([#3208](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3208))
1618
- VertexAI emit user, system, and assistant events
1719
([#3203](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3203))
18-
- Add Vertex gen AI response span attributes
20+
- Add Vertex gen AI response attributes and `gen_ai.choice` events
1921
([#3227](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3227))
2022
- VertexAI stop serializing unset fields into event
2123
([#3236](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3236))
24+
- Vertex capture tool requests and responses
25+
([#3255](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3255))

instrumentation-genai/opentelemetry-instrumentation-vertexai/README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
OpenTelemetry VertexAI Instrumentation
2-
====================================
2+
======================================
33

44
|pypi|
55

instrumentation-genai/opentelemetry-instrumentation-vertexai/src/opentelemetry/instrumentation/vertexai/events.py

+57-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from __future__ import annotations
2424

2525
from dataclasses import asdict, dataclass
26-
from typing import Literal
26+
from typing import Any, Iterable, Literal
2727

2828
from opentelemetry._events import Event
2929
from opentelemetry.semconv._incubating.attributes import gen_ai_attributes
@@ -96,6 +96,33 @@ def system_event(
9696
)
9797

9898

99+
def tool_event(
100+
*,
101+
role: str | None,
102+
id_: str,
103+
content: AnyValue = None,
104+
) -> Event:
105+
"""Creates a Tool message event
106+
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#event-gen_aitoolmessage
107+
"""
108+
if not role:
109+
role = "tool"
110+
111+
body: dict[str, AnyValue] = {
112+
"role": role,
113+
"id": id_,
114+
}
115+
if content is not None:
116+
body["content"] = content
117+
return Event(
118+
name="gen_ai.tool.message",
119+
attributes={
120+
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
121+
},
122+
body=body,
123+
)
124+
125+
99126
@dataclass
100127
class ChoiceMessage:
101128
"""The message field for a gen_ai.choice event"""
@@ -104,36 +131,58 @@ class ChoiceMessage:
104131
role: str = "assistant"
105132

106133

134+
@dataclass
135+
class ChoiceToolCall:
136+
"""The tool_calls field for a gen_ai.choice event"""
137+
138+
@dataclass
139+
class Function:
140+
name: str
141+
arguments: AnyValue = None
142+
143+
function: Function
144+
id: str
145+
type: Literal["function"] = "function"
146+
147+
107148
FinishReason = Literal[
108149
"content_filter", "error", "length", "stop", "tool_calls"
109150
]
110151

111152

112-
# TODO add tool calls
113-
# https://github.com/open-telemetry/opentelemetry-python-contrib/issues/3216
114153
def choice_event(
115154
*,
116155
finish_reason: FinishReason | str,
117156
index: int,
118157
message: ChoiceMessage,
158+
tool_calls: Iterable[ChoiceToolCall] = (),
119159
) -> Event:
120160
"""Creates a choice event, which describes the Gen AI response message.
121161
https://github.com/open-telemetry/semantic-conventions/blob/v1.28.0/docs/gen-ai/gen-ai-events.md#event-gen_aichoice
122162
"""
123163
body: dict[str, AnyValue] = {
124164
"finish_reason": finish_reason,
125165
"index": index,
126-
"message": asdict(
127-
message,
128-
# filter nulls
129-
dict_factory=lambda kvs: {k: v for (k, v) in kvs if v is not None},
130-
),
166+
"message": _asdict_filter_nulls(message),
131167
}
132168

169+
tool_calls_list = [
170+
_asdict_filter_nulls(tool_call) for tool_call in tool_calls
171+
]
172+
if tool_calls_list:
173+
body["tool_calls"] = tool_calls_list
174+
133175
return Event(
134176
name="gen_ai.choice",
135177
attributes={
136178
gen_ai_attributes.GEN_AI_SYSTEM: gen_ai_attributes.GenAiSystemValues.VERTEX_AI.value,
137179
},
138180
body=body,
139181
)
182+
183+
184+
def _asdict_filter_nulls(instance: Any) -> dict[str, AnyValue]:
185+
return asdict(
186+
instance,
187+
dict_factory=lambda kvs: {k: v for (k, v) in kvs if v is not None},
188+
)

0 commit comments

Comments
 (0)