Skip to content

Commit

Permalink
Merge branch 'main' into db-statement-with-sqlcomment
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi authored Nov 4, 2024
2 parents 6c14f72 + 3109724 commit 3b383cd
Show file tree
Hide file tree
Showing 40 changed files with 3,534 additions and 744 deletions.
5 changes: 5 additions & 0 deletions .github/component_owners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ components:

processor/opentelemetry-processor-baggage:
- codeboten

instrumentation-genai/:
- karthikscale3
- lmolkova
- lzchen
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2922](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2922))
- `opentelemetry-instrumentation-celery` Don't detach context without a None token
([#2927](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2927))
- `opentelemetry-exporter-prometheus-remote-write`: sort labels before exporting
([#2940](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2940))
- `opentelemetry-instrumentation-dbapi` sqlcommenter key values created from PostgreSQL, MySQL systems
([#2897](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2897))

### Breaking changes

Expand Down
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Please also read the [OpenTelemetry Contributor Guide](https://github.com/open-t
* [Testing against a different Core repo branch/commit](#testing-against-a-different-core-repo-branchcommit)
* [Style Guide](#style-guide)
* [Guideline for instrumentations](#guideline-for-instrumentations)
* [Guidance for GenAI instrumentations](#guideline-for-genai-instrumentations)
* [Expectations from contributors](#expectations-from-contributors)

## Find a Buddy and get Started Quickly
Expand Down Expand Up @@ -272,6 +273,18 @@ Below is a checklist of things to be mindful of when implementing a new instrume
- ex. <https://github.com/open-telemetry/opentelemetry-python-contrib/blob/60fb936b7e5371b3e5587074906c49fb873cbd76/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py#L84>
- All instrumentations have the same version. If you are going to develop a new instrumentation it would probably have `X.Y.dev` version and depends on `opentelemetry-instrumentation` and `opentelemetry-semantic-conventions` for the same version. That means that if you want to install your instrumentation you need to install its dependencies from this repo and the core repo also from git.

## Guidance for GenAI instrumentations

Instrumentations that relate to [Generative AI](https://opentelemetry.io/docs/specs/semconv/gen-ai/) systems will be placed in the [genai](./instrumentation/genai) folder. This section covers contributions related to those instrumentations. Please note that the [guidelines for instrumentations](#guideline-for-instrumentations) and [expectations from contributors](#expectations-from-contributors) still apply.

### Get Involved

* Reviewing PRs: If you would like to be tagged as reviewer in new PRs related to these instrumentations, please submit a PR to add your GitHub handle to [component_owners.yml](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2944/.github/component_owners.yml) under the corresponding instrumentation folder(s).

* Approving PRs: If you would like to be able to approve PRs related to these instrumentations, you must join [opentelemetry-python-contrib-approvers](https://github.com/orgs/open-telemetry/teams/opentelemetry-python-contrib-approvers) team. Please ask one of the [Python contrib maintainers](https://github.com/orgs/open-telemetry/teams/opentelemetry-python-contrib-maintainers) to be accepted into the team.

* Tracking and Creating Issues: For tracking issues related to Generative AI, please filter or add the label [gen-ai](https://github.com/open-telemetry/opentelemetry-python-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Agen-ai) when creating or searching issues. If you do not see an issue related to an instrumentation you would like to contribute to, please create a new tracking issue so the community is aware of its progress.

## Expectations from contributors

OpenTelemetry is an open source community, and as such, greatly encourages contributions from anyone interested in the project. With that being said, there is a certain level of expectation from contributors even after a pull request is merged, specifically pertaining to instrumentations. The OpenTelemetry Python community expects contributors to maintain a level of support and interest in the instrumentations they contribute. This is to ensure that the instrumentation does not become stale and still functions the way the original contributor intended. Some instrumentations also pertain to libraries that the current members of the community are not so familiar with, so it is necessary to rely on the expertise of the original contributing parties.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ Emeritus Approvers:
Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-telemetry/teams/python-maintainers)):

- [Aaron Abbott](https://github.com/aabmass), Google
- [Diego Hurtado](https://github.com/ocelotl), Lightstep
- [Leighton Chen](https://github.com/lzchen), Microsoft
- [Riccardo Magliocchetti](https://github.com/xrmx), Elastic
- [Shalev Roda](https://github.com/shalevr), Cisco

Emeritus Maintainers:

- [Alex Boten](https://github.com/codeboten), Lightstep
- [Diego Hurtado](https://github.com/ocelotl), Lightstep
- [Owais Lone](https://github.com/owais), Splunk
- [Yusuke Tsutsumi](https://github.com/toumorokoshi), Google

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import re
from collections import defaultdict
from itertools import chain
from typing import Dict, Sequence
from typing import Dict, Mapping, Sequence

import requests
import snappy
Expand Down Expand Up @@ -253,12 +253,14 @@ def _parse_metric(
return self._convert_to_timeseries(sample_sets, resource_labels)

def _convert_to_timeseries(
self, sample_sets: Sequence[tuple], resource_labels: Sequence
self, sample_sets: Mapping[tuple, Sequence], resource_labels: Sequence
) -> Sequence[TimeSeries]:
timeseries = []
for labels, samples in sample_sets.items():
ts = TimeSeries()
for label_name, label_value in chain(resource_labels, labels):
for label_name, label_value in sorted(
chain(resource_labels, labels)
):
# Previous implementation did not str() the names...
ts.labels.append(self._label(label_name, str(label_value)))
for value, timestamp in samples:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
PrometheusRemoteWriteMetricsExporter,
)
from opentelemetry.exporter.prometheus_remote_write.gen.types_pb2 import ( # pylint: disable=E0611
Label,
Sample,
TimeSeries,
)
from opentelemetry.sdk.metrics.export import (
Expand Down Expand Up @@ -155,6 +157,38 @@ def test_parse_metric(metric, prom_rw):
assert sample.value in values


def test_convert_to_timeseries(prom_rw):
resource_labels = (("service_name", "foo"), ("bool_value", True))
sample_sets = {
(("foo", "bar"), ("baz", 42), ("__name__", "test_histogram_tu")): [
(1, 1641946016139)
],
(("baz", "42"), ("foo", "bar")): [(4, 1641946016139)],
}
timeseries = prom_rw._convert_to_timeseries(sample_sets, resource_labels)
assert timeseries == [
TimeSeries(
labels=[
Label(name="__name__", value="test_histogram_tu"),
Label(name="baz", value="42"),
Label(name="bool_value", value="True"),
Label(name="foo", value="bar"),
Label(name="service_name", value="foo"),
],
samples=[Sample(value=1, timestamp=1641946016139)],
),
TimeSeries(
labels=[
Label(name="baz", value="42"),
Label(name="bool_value", value="True"),
Label(name="foo", value="bar"),
Label(name="service_name", value="foo"),
],
samples=[Sample(value=4, timestamp=1641946016139)],
),
]


class TestValidation(unittest.TestCase):
# Test cases to ensure exporter parameter validation works as intended
def test_valid_standard_param(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- Update OpenAI instrumentation to Semantic Conventions v1.28.0: add new attributes
and switch prompts and completions to log-based events.
([#2925](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2925))

- Initial OpenAI instrumentation
([#2759](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2759))
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
OpenTelemetry OpenAI Instrumentation
====================================
====================================

|pypi|

.. |pypi| image:: https://badge.fury.io/py/opentelemetry-instrumentation-openai-v2.svg
:target: https://pypi.org/project/opentelemetry-instrumentation-openai-v2/

Instrumentation with OpenAI that supports the openai library and is
Instrumentation with OpenAI that supports the OpenAI library and is
specified to trace_integration using 'OpenAI'.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.. code:: python
from openai import OpenAI
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
OpenAIInstrumentor().instrument()
Expand All @@ -44,8 +44,10 @@

from wrapt import wrap_function_wrapper

from opentelemetry._events import get_event_logger
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.openai_v2.package import _instruments
from opentelemetry.instrumentation.openai_v2.utils import is_content_enabled
from opentelemetry.instrumentation.utils import unwrap
from opentelemetry.semconv.schemas import Schemas
from opentelemetry.trace import get_tracer
Expand All @@ -64,15 +66,25 @@ def _instrument(self, **kwargs):
__name__,
"",
tracer_provider,
schema_url=Schemas.V1_27_0.value,
schema_url=Schemas.V1_28_0.value,
)
event_logger_provider = kwargs.get("event_logger_provider")
event_logger = get_event_logger(
__name__,
"",
schema_url=Schemas.V1_28_0.value,
event_logger_provider=event_logger_provider,
)

wrap_function_wrapper(
module="openai.resources.chat.completions",
name="Completions.create",
wrapper=chat_completions_create(tracer),
wrapper=chat_completions_create(
tracer, event_logger, is_content_enabled()
),
)

def _uninstrument(self, **kwargs):
import openai
import openai # pylint: disable=import-outside-toplevel

unwrap(openai.resources.chat.completions.Completions, "create")
Loading

0 comments on commit 3b383cd

Please sign in to comment.