Skip to content

Commit

Permalink
Merge branch 'main' into os-resource-detector
Browse files Browse the repository at this point in the history
  • Loading branch information
Zirak committed Jul 21, 2024
2 parents 1f3becf + 6631e89 commit 12162ed
Show file tree
Hide file tree
Showing 55 changed files with 1,218 additions and 558 deletions.
1 change: 0 additions & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:

jobs:
sdk-benchmarks:
env:
runs-on: self-hosted
steps:
- name: Checkout Core Repo @ SHA - ${{ github.sha }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
# Otherwise, set variable to the commit of your branch on
# opentelemetry-python-contrib which is compatible with these Core repo
# changes.
CONTRIB_REPO_SHA: 7d4573da89c7aef748614e6f1511be3eddf5b230
CONTRIB_REPO_SHA: main

# This is needed because we do not clone the core repo in contrib builds anymore.
# When running contrib builds as part of core builds, we use actions/checkout@v4 which
Expand Down Expand Up @@ -174,7 +174,6 @@ jobs:
- "redis"
- "remoulade"
- "requests"
- "sklearn"
- "sqlalchemy"
- "sqlite3"
- "starlette"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- optional scope attributes for logger creation
([#4035](https://github.com/open-telemetry/opentelemetry-python/pull/4035))
- optional scope attribute for tracer creation
([#4028](https://github.com/open-telemetry/opentelemetry-python/pull/4028))
- OTLP exporter is encoding invalid span/trace IDs in the logs fix
([#4006](https://github.com/open-telemetry/opentelemetry-python/pull/4006))
- Update sdk process resource detector `process.command_args` attribute to also include the executable itself
Expand All @@ -21,6 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3956](https://github.com/open-telemetry/opentelemetry-python/pull/3956))
- When encountering an error encoding metric attributes in the OTLP exporter, log the key that had an error.
([#3838](https://github.com/open-telemetry/opentelemetry-python/pull/3838))
- Fix `ExponentialHistogramAggregation`
([#3978](https://github.com/open-telemetry/opentelemetry-python/pull/3978))
- Log a warning when a `LogRecord` in `sdk/log` has dropped attributes
due to reaching limits
([#3946](https://github.com/open-telemetry/opentelemetry-python/pull/3946))
Expand Down
4 changes: 4 additions & 0 deletions docs-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ sphinx-jekyll-builder==0.3.0
./opentelemetry-api
./opentelemetry-semantic-conventions
./opentelemetry-sdk
./opentelemetry-proto
./shim/opentelemetry-opencensus-shim
./shim/opentelemetry-opentracing-shim
./exporter/opentelemetry-exporter-otlp-proto-common
./exporter/opentelemetry-exporter-otlp-proto-http
./exporter/opentelemetry-exporter-otlp-proto-grpc

# Required by instrumentation and exporter packages
grpcio~=1.27
Expand Down
23 changes: 23 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@
"py:class",
"opentelemetry.trace._LinkBase",
),
(
"py:class",
"opentelemetry.exporter.otlp.proto.grpc.exporter.OTLPExporterMixin",
),
(
"py:class",
"opentelemetry.proto.collector.trace.v1.trace_service_pb2.ExportTraceServiceRequest",
),
(
"py:class",
"opentelemetry.exporter.otlp.proto.common._internal.metrics_encoder.OTLPMetricExporterMixin",
),
("py:class", "opentelemetry.proto.resource.v1.resource_pb2.Resource"),
(
"py:class",
"opentelemetry.proto.collector.metrics.v1.metrics_service_pb2.ExportMetricsServiceRequest",
),
("py:class", "opentelemetry.sdk._logs._internal.export.LogExporter"),
("py:class", "opentelemetry.sdk._logs._internal.export.LogExportResult"),
(
"py:class",
"opentelemetry.proto.collector.logs.v1.logs_service_pb2.ExportLogsServiceRequest",
),
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
15 changes: 10 additions & 5 deletions docs/examples/logs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@ Start the Collector locally to see data being exported. Write the following file
otlp:
protocols:
grpc:
processors:
batch:
endpoint: 0.0.0.0:4317
exporters:
logging:
verbosity: detailed
loglevel: debug
processors:
batch:
service:
pipelines:
logs:
receivers: [otlp]
processors: [batch]
exporters: [logging]
traces:
receivers: [otlp]
processors: [batch]
exporters: [logging]
Then start the Docker container:

.. code-block:: sh
Expand Down
1 change: 1 addition & 0 deletions docs/examples/logs/otel-collector-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317

exporters:
logging:
Expand Down
1 change: 1 addition & 0 deletions docs/examples/metrics/instruments/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Start the Collector locally to see data being exported. Write the following file
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
exporters:
logging:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317

exporters:
logging:
Expand Down
24 changes: 23 additions & 1 deletion docs/exporter/otlp/otlp.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
OpenTelemetry OTLP Exporters
============================

.. automodule:: opentelemetry.exporter.otlp
:members:
:undoc-members:
:show-inheritance:

opentelemetry.exporter.otlp.proto.http
---------------------------------------

.. automodule:: opentelemetry.exporter.otlp.proto.http
:members:
:undoc-members:
:show-inheritance:

.. automodule:: opentelemetry.exporter.otlp.proto.http.trace_exporter

.. automodule:: opentelemetry.exporter.otlp.proto.http.metric_exporter

.. automodule:: opentelemetry.exporter.otlp.proto.http._log_exporter

opentelemetry.exporter.otlp.proto.grpc
---------------------------------------

.. automodule:: opentelemetry.exporter.otlp.proto.grpc
:members:
:undoc-members:
:show-inheritance:

.. automodule:: opentelemetry.exporter.otlp.proto.grpc.trace_exporter

.. automodule:: opentelemetry.exporter.otlp.proto.grpc.metric_exporter

.. automodule:: opentelemetry.exporter.otlp.proto.grpc._log_exporter
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# pylint: disable=invalid-name

from unittest.mock import patch

from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
Expand Down
20 changes: 18 additions & 2 deletions opentelemetry-api/src/opentelemetry/_logs/_internal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,13 @@ def __init__(
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
) -> None:
super().__init__()
self._name = name
self._version = version
self._schema_url = schema_url
self._attributes = attributes

@abstractmethod
def emit(self, record: "LogRecord") -> None:
Expand All @@ -117,10 +119,12 @@ def __init__( # pylint: disable=super-init-not-called
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
):
self._name = name
self._version = version
self._schema_url = schema_url
self._attributes = attributes
self._real_logger: Optional[Logger] = None
self._noop_logger = NoOpLogger(name)

Expand All @@ -134,6 +138,7 @@ def _logger(self) -> Logger:
self._name,
self._version,
self._schema_url,
self._attributes,
)
return self._real_logger
return self._noop_logger
Expand All @@ -153,6 +158,7 @@ def get_logger(
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
) -> Logger:
"""Returns a `Logger` for use by the given instrumentation library.
Expand Down Expand Up @@ -190,9 +196,12 @@ def get_logger(
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
) -> Logger:
"""Returns a NoOpLogger."""
return NoOpLogger(name, version=version, schema_url=schema_url)
return NoOpLogger(
name, version=version, schema_url=schema_url, attributes=attributes
)


class ProxyLoggerProvider(LoggerProvider):
Expand All @@ -201,17 +210,20 @@ def get_logger(
name: str,
version: Optional[str] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
) -> Logger:
if _LOGGER_PROVIDER:
return _LOGGER_PROVIDER.get_logger(
name,
version=version,
schema_url=schema_url,
attributes=attributes,
)
return ProxyLogger(
name,
version=version,
schema_url=schema_url,
attributes=attributes,
)


Expand Down Expand Up @@ -261,6 +273,7 @@ def get_logger(
instrumenting_library_version: str = "",
logger_provider: Optional[LoggerProvider] = None,
schema_url: Optional[str] = None,
attributes: Optional[Attributes] = None,
) -> "Logger":
"""Returns a `Logger` for use within a python process.
Expand All @@ -272,5 +285,8 @@ def get_logger(
if logger_provider is None:
logger_provider = get_logger_provider()
return logger_provider.get_logger(
instrumenting_module_name, instrumenting_library_version, schema_url
instrumenting_module_name,
instrumenting_library_version,
schema_url,
attributes,
)
15 changes: 14 additions & 1 deletion opentelemetry-api/src/opentelemetry/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def get_tracer(
instrumenting_module_name: str,
instrumenting_library_version: typing.Optional[str] = None,
schema_url: typing.Optional[str] = None,
attributes: typing.Optional[types.Attributes] = None,
) -> "Tracer":
"""Returns a `Tracer` for use by the given instrumentation library.
Expand Down Expand Up @@ -216,6 +217,7 @@ def get_tracer(
``importlib.metadata.version(instrumenting_library_name)``.
schema_url: Optional. Specifies the Schema URL of the emitted telemetry.
attributes: Optional. Specifies the attributes of the emitted telemetry.
"""


Expand All @@ -230,6 +232,7 @@ def get_tracer(
instrumenting_module_name: str,
instrumenting_library_version: typing.Optional[str] = None,
schema_url: typing.Optional[str] = None,
attributes: typing.Optional[types.Attributes] = None,
) -> "Tracer":
# pylint:disable=no-self-use,unused-argument
return NoOpTracer()
Expand All @@ -249,17 +252,20 @@ def get_tracer(
instrumenting_module_name: str,
instrumenting_library_version: typing.Optional[str] = None,
schema_url: typing.Optional[str] = None,
attributes: typing.Optional[types.Attributes] = None,
) -> "Tracer":
if _TRACER_PROVIDER:
return _TRACER_PROVIDER.get_tracer(
instrumenting_module_name,
instrumenting_library_version,
schema_url,
attributes,
)
return ProxyTracer(
instrumenting_module_name,
instrumenting_library_version,
schema_url,
attributes,
)


Expand Down Expand Up @@ -407,10 +413,12 @@ def __init__(
instrumenting_module_name: str,
instrumenting_library_version: typing.Optional[str] = None,
schema_url: typing.Optional[str] = None,
attributes: typing.Optional[types.Attributes] = None,
):
self._instrumenting_module_name = instrumenting_module_name
self._instrumenting_library_version = instrumenting_library_version
self._schema_url = schema_url
self._attributes = attributes
self._real_tracer: Optional[Tracer] = None
self._noop_tracer = NoOpTracer()

Expand All @@ -424,6 +432,7 @@ def _tracer(self) -> Tracer:
self._instrumenting_module_name,
self._instrumenting_library_version,
self._schema_url,
self._attributes,
)
return self._real_tracer
return self._noop_tracer
Expand Down Expand Up @@ -492,6 +501,7 @@ def get_tracer(
instrumenting_library_version: typing.Optional[str] = None,
tracer_provider: Optional[TracerProvider] = None,
schema_url: typing.Optional[str] = None,
attributes: typing.Optional[types.Attributes] = None,
) -> "Tracer":
"""Returns a `Tracer` for use by the given instrumentation library.
Expand All @@ -503,7 +513,10 @@ def get_tracer(
if tracer_provider is None:
tracer_provider = get_tracer_provider()
return tracer_provider.get_tracer(
instrumenting_module_name, instrumenting_library_version, schema_url
instrumenting_module_name,
instrumenting_library_version,
schema_url,
attributes,
)


Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-api/tests/attributes/test_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class TestAttributes(unittest.TestCase):
# pylint: disable=invalid-name
def assertValid(self, value, key="k"):
expected = value
if isinstance(value, MutableSequence):
Expand Down Expand Up @@ -89,6 +90,7 @@ def test_sequence_attr_decode(self):


class TestBoundedAttributes(unittest.TestCase):
# pylint: disable=consider-using-dict-items
base = {
"name": "Firulais",
"age": 7,
Expand Down Expand Up @@ -188,7 +190,7 @@ def test_locking(self):
"""
bdict = BoundedAttributes(immutable=False)

with bdict._lock:
with bdict._lock: # pylint: disable=protected-access
for num in range(100):
bdict[str(num)] = num

Expand Down
Loading

0 comments on commit 12162ed

Please sign in to comment.