-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87ff39a
commit 9c55ffc
Showing
11 changed files
with
189 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from lumigo_opentelemetry import logger_provider | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
logger.setLevel(logging.DEBUG) | ||
|
||
logger.debug("Hello OTEL!") | ||
|
||
logger_provider.force_flush() | ||
logger_provider.shutdown() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
import unittest | ||
from os import path | ||
from test.test_utils.logs_parser import LogsContainer | ||
|
||
|
||
def run_logging_app(): | ||
sample_path = path.join( | ||
path.dirname(path.abspath(__file__)), | ||
"../app/logging_app.py", | ||
) | ||
subprocess.check_output( | ||
[sys.executable, sample_path], | ||
env={ | ||
**os.environ, | ||
"AUTOWRAPT_BOOTSTRAP": "lumigo_opentelemetry", | ||
"OTEL_SERVICE_NAME": "logging-app", | ||
"LUMIGO_LOGS_ENABLED": "true", | ||
}, | ||
) | ||
|
||
|
||
class TestLogging(unittest.TestCase): | ||
def test_logging(self): | ||
run_logging_app() | ||
|
||
logs_container = LogsContainer.get_logs_from_file() | ||
|
||
self.assertEqual(len(logs_container), 1) | ||
|
||
logs_container[0]["body"] == "Hello OTEL!" | ||
|
||
# "resource" is currently not a proper dictionary, but a string from a repr(...) call over the resource attributes. | ||
# Pending a fix in https://github.com/open-telemetry/opentelemetry-python/pull/3346 | ||
logs_container[0]["resource"]["service.name"] == "logging-app" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
import os | ||
import time | ||
from dataclasses import dataclass | ||
from typing import Any, Dict, List, Optional | ||
|
||
LOGS_FILE_FULL_PATH = os.environ.get("LUMIGO_DEBUG_LOGDUMP") | ||
|
||
|
||
@dataclass(frozen=True) | ||
class LogsContainer: | ||
logs: List[Dict[str, Any]] | ||
|
||
@staticmethod | ||
def get_logs_from_file( | ||
path: Optional[str] = LOGS_FILE_FULL_PATH, | ||
wait_time_sec: int = 3, | ||
) -> LogsContainer: | ||
time.sleep(wait_time_sec) | ||
|
||
try: | ||
with open(path) as file: | ||
logs = [json.loads(line) for line in file.readlines()] | ||
|
||
return LogsContainer(logs=logs) | ||
|
||
except Exception as err: | ||
print(f"Failed to parse logs from file after {wait_time_sec}s: {err}") | ||
|
||
return LogsContainer(logs=[]) | ||
|
||
def __len__(self) -> int: | ||
return len(self.logs) | ||
|
||
def __getitem__(self, item) -> Dict[str, Any]: | ||
return self.logs[item] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters