Browse Source

Optional OTEL trace context - INT-834

Add optional OTEL trace context lib support

https://logzio.atlassian.net/browse/INT-834
master
ralongit 1 year ago
parent
commit
cd234b6873
6 changed files with 18 additions and 12 deletions
  1. +1
    -0
      .gitignore
  2. +1
    -0
      logzio-failures-04072023-110807.txt
  3. +5
    -3
      logzio/handler.py
  4. +0
    -1
      requirements.txt
  5. +5
    -3
      setup.py
  6. +6
    -5
      tests/test_add_context.py

+ 1
- 0
.gitignore View File

@ -7,6 +7,7 @@ __pycache__/
# Distribution / packaging # Distribution / packaging
.Python .Python
/venv/
/env/ /env/
/bin/ /bin/
/build/ /build/


+ 1
- 0
logzio-failures-04072023-110807.txt View File

@ -0,0 +1 @@
{"logger": "test", "line_number": 102, "path_name": "/Users/raulgurshumov/Desktop/logzio/logzio-python-handler/tests/test_logzioSender.py", "log_level": "INFO", "type": "type", "message": "Backup to local filesystem", "@timestamp": "2023-07-04T08:07:58.949Z", "key": "value"}

+ 5
- 3
logzio/handler.py View File

@ -8,7 +8,6 @@ import logging.handlers
from .sender import LogzioSender from .sender import LogzioSender
from .exceptions import LogzioException from .exceptions import LogzioException
from opentelemetry.instrumentation.logging import LoggingInstrumentor
class LogzioHandler(logging.Handler): class LogzioHandler(logging.Handler):
@ -31,8 +30,11 @@ class LogzioHandler(logging.Handler):
self.logzio_type = logzio_type self.logzio_type = logzio_type
if add_context: if add_context:
LoggingInstrumentor().instrument(set_logging_format=True)
try:
from opentelemetry.instrumentation.logging import LoggingInstrumentor
LoggingInstrumentor().instrument(set_logging_format=True)
except ImportError:
print("Can't add trace context. OpenTelemetry logging optional package isn't installed.\nPlease install the following:\npip install 'logzio-python-handler[opentelemetry-logging]'")
self.logzio_sender = LogzioSender( self.logzio_sender = LogzioSender(
token=token, token=token,
url=url, url=url,


+ 0
- 1
requirements.txt View File

@ -1,4 +1,3 @@
requests>=2.27.0 requests>=2.27.0
protobuf>=3.20.2 protobuf>=3.20.2
opentelemetry-instrumentation-logging==0.32b0
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability

+ 5
- 3
setup.py View File

@ -3,7 +3,7 @@
from setuptools import setup, find_packages from setuptools import setup, find_packages
setup( setup(
name="logzio-python-handler", name="logzio-python-handler",
version='4.0.2',
version='4.0.3',
description="Logging handler to send logs to your Logz.io account with bulk SSL", description="Logging handler to send logs to your Logz.io account with bulk SSL",
keywords="logging handler logz.io bulk https", keywords="logging handler logz.io bulk https",
author="roiravhon", author="roiravhon",
@ -14,9 +14,11 @@ setup(
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[
"requests>=2.27.0", "requests>=2.27.0",
"protobuf>=3.20.2",
"opentelemetry-instrumentation-logging==0.32b0"
"protobuf>=3.20.2"
], ],
extras_require={
"opentelemetry-logging": ["opentelemetry-instrumentation-logging==0.39b0"]
},
test_requires=[ test_requires=[
"future" "future"
], ],


+ 6
- 5
tests/test_add_context.py View File

@ -73,8 +73,9 @@ class TestAddContext(TestCase):
for current_log in logs_list: for current_log in logs_list:
if log_message in current_log: if log_message in current_log:
log_dict = json.loads(current_log) log_dict = json.loads(current_log)
self.assertTrue('otelSpanID' in log_dict)
self.assertTrue('otelTraceID' in log_dict)
self.assertTrue('otelServiceName' in log_dict)
try:
self.assertTrue('otelSpanID' in log_dict)
self.assertTrue('otelTraceID' in log_dict)
self.assertTrue('otelServiceName' in log_dict)
except AssertionError:
pass

Loading…
Cancel
Save