Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logging to include logging api as per specification #3038

Merged
merged 31 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .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: 66edf69811e142c397d8500cafe6eddeb5565d6e
CONTRIB_REPO_SHA: c6134843900e2eeb1b8b3383a897b38cc0905c38
# 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@v2 which
# does not set an environment variable (simply just runs tox), which is different when
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Add missing entry points for OTLP/HTTP exporter
([#3027](https://github.com/open-telemetry/opentelemetry-python/pull/3027))
- Implement logging API
([#3038](https://github.com/open-telemetry/opentelemetry-python/pull/3038))
lzchen marked this conversation as resolved.
Show resolved Hide resolved

## Version 1.14.0/0.35b0 (2022-11-04)

Expand Down
1 change: 1 addition & 0 deletions docs/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ OpenTelemetry Python API

baggage
context
logs
propagate
propagators
trace
Expand Down
22 changes: 22 additions & 0 deletions docs/api/logs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
opentelemetry._logs package
===========================

.. warning::
OpenTelemetry Python logs are in an experimental state. The APIs within
:mod:`opentelemetry._logs` are subject to change in minor/patch releases and make no
backward compatibility guarantees at this time.

Once logs become stable, this package will be be renamed to ``opentelemetry.logs``.

Submodules
----------

.. toctree::

logs.severity


Module contents
---------------

.. automodule:: opentelemetry._logs
7 changes: 7 additions & 0 deletions docs/api/logs.severity.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
opentelemetry._logs.severity
============================

.. automodule:: opentelemetry._logs.severity
:members:
:undoc-members:
:show-inheritance:
4 changes: 3 additions & 1 deletion docs/sdk/logs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Submodules
.. toctree::

logs.export
logs.severity

Module contents
---------------

.. automodule:: opentelemetry.sdk._logs
:members:
Expand Down
7 changes: 0 additions & 7 deletions docs/sdk/logs.severity.rst

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from google.rpc.error_details_pb2 import RetryInfo
from grpc import StatusCode, server

from opentelemetry._logs import SeverityNumber
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
OTLPLogExporter,
)
Expand All @@ -45,9 +46,6 @@
)
from opentelemetry.sdk._logs import LogData, LogRecord
from opentelemetry.sdk._logs.export import LogExportResult
from opentelemetry.sdk._logs.severity import (
SeverityNumber as SDKSeverityNumber,
)
from opentelemetry.sdk.resources import Resource as SDKResource
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
from opentelemetry.trace import TraceFlags
Expand Down Expand Up @@ -117,7 +115,7 @@ def setUp(self):
span_id=5213367945872657620,
trace_flags=TraceFlags(0x01),
severity_text="WARNING",
severity_number=SDKSeverityNumber.WARN,
severity_number=SeverityNumber.WARN,
body="Zhengzhou, We have a heaviest rains in 1000 years",
resource=SDKResource({"key": "value"}),
attributes={"a": 1, "b": "c"},
Expand All @@ -133,7 +131,7 @@ def setUp(self):
span_id=5213367945872657623,
trace_flags=TraceFlags(0x01),
severity_text="INFO",
severity_number=SDKSeverityNumber.INFO2,
severity_number=SeverityNumber.INFO2,
body="Sydney, Opera House is closed",
resource=SDKResource({"key": "value"}),
attributes={"custom_attr": [1, 2, 3]},
Expand All @@ -149,7 +147,7 @@ def setUp(self):
span_id=5213367945872657628,
trace_flags=TraceFlags(0x01),
severity_text="ERROR",
severity_number=SDKSeverityNumber.WARN,
severity_number=SeverityNumber.WARN,
body="Mumbai, Boil water before drinking",
resource=SDKResource({"service": "myapp"}),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import requests
import responses

from opentelemetry._logs import SeverityNumber
from opentelemetry.exporter.otlp.proto.http import Compression
from opentelemetry.exporter.otlp.proto.http._log_exporter import (
DEFAULT_COMPRESSION,
Expand Down Expand Up @@ -54,7 +55,6 @@
)
from opentelemetry.sdk._logs import LogData
from opentelemetry.sdk._logs import LogRecord as SDKLogRecord
from opentelemetry.sdk._logs.severity import SeverityNumber
from opentelemetry.sdk.environment_variables import (
OTEL_EXPORTER_OTLP_CERTIFICATE,
OTEL_EXPORTER_OTLP_COMPRESSION,
Expand Down
60 changes: 60 additions & 0 deletions opentelemetry-api/src/opentelemetry/_logs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
The OpenTelemetry logging API describes the classes used to generate logs and events.

The :class:`.LoggerProvider` provides users access to the :class:`.Logger` which in
turn is used to create :class:`.Event` and :class:`.Log` objects.

This module provides abstract (i.e. unimplemented) classes required for
logging, and a concrete no-op implementation :class:`.NoOpLogger` that allows applications
to use the API package alone without a supporting implementation.

To get a logger, you need to provide the package name from which you are
calling the logging APIs to OpenTelemetry by calling `LoggerProvider.get_logger`
with the calling module name and the version of your package.

The following code shows how to obtain a logger using the global :class:`.LoggerProvider`::

from opentelemetry._logs import get_logger

logger = get_logger("example-logger")

.. versionadded:: 1.15.0
"""

from opentelemetry._logs._internal import (
Logger,
LoggerProvider,
LogRecord,
NoOpLogger,
NoOpLoggerProvider,
get_logger,
get_logger_provider,
set_logger_provider,
)
from opentelemetry._logs.severity import SeverityNumber, std_to_otel

__all__ = [
lzchen marked this conversation as resolved.
Show resolved Hide resolved
"Logger",
"LoggerProvider",
"LogRecord",
"NoOpLogger",
"NoOpLoggerProvider",
"SeverityNumber",
"get_logger",
"get_logger_provider",
"set_logger_provider",
"std_to_otel",
]
Loading