-
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
0fb3347
commit a3ad86c
Showing
6 changed files
with
159 additions
and
122 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from test.test_utils.processes import kill_process | ||
|
||
|
||
class FastApiSample(object): | ||
def __init__(self): | ||
cwd = Path(__file__).parent.parent | ||
print(f"cwd = {cwd}") | ||
env = { | ||
**os.environ, | ||
"AUTOWRAPT_BOOTSTRAP": "lumigo_opentelemetry", | ||
"LUMIGO_DEBUG_SPANDUMP": os.environ["LUMIGO_DEBUG_SPANDUMP"], | ||
"OTEL_SERVICE_NAME": "fastapi_test_app", | ||
} | ||
print(f"env = {env}") | ||
venv_bin_path = Path(sys.executable).parent | ||
print(f"venv_bin_path = {venv_bin_path}") | ||
cmd = f". {venv_bin_path}/activate; uvicorn app:app --port 8000" | ||
print(f"cmd = {cmd}") | ||
self.process = subprocess.Popen( | ||
cmd, | ||
cwd=cwd, | ||
env=env, | ||
shell=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
is_app_running = False | ||
for line in self.process.stderr: | ||
if "Uvicorn running" in str(line): | ||
print(f"FastApiSample app: {line}") | ||
is_app_running = True | ||
break | ||
print(line) | ||
if not is_app_running: | ||
raise Exception("FastApiSample app failed to start") | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
# because we need a shell to run uvicorn we need to kill multiple processs, | ||
# but not the process group because that includes the test process as well | ||
kill_process("uvicorn") |
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 |
---|---|---|
@@ -1,39 +1,44 @@ | ||
import unittest | ||
from test.test_utils.span_exporter import wait_for_exporter | ||
from test.test_utils.spans_parser import SpansContainer | ||
|
||
import requests | ||
|
||
from .app_runner import FastApiSample | ||
|
||
|
||
class TestLargeSpans(unittest.TestCase): | ||
def test_large_span_attribute_size_max_size_env_var_was_set(self): | ||
response = requests.get("http://localhost:8020/invoke-requests-large-response") | ||
response.raise_for_status() | ||
|
||
body = response.json() | ||
with FastApiSample(): | ||
response = requests.get( | ||
"http://localhost:8020/invoke-requests-large-response" | ||
) | ||
response.raise_for_status() | ||
|
||
assert body is not None | ||
body = response.json() | ||
|
||
wait_for_exporter() | ||
assert body is not None | ||
|
||
spans_container = SpansContainer.get_spans_from_file() | ||
self.assertEqual(4, len(spans_container.spans)) | ||
spans_container = SpansContainer.get_spans_from_file( | ||
wait_time_sec=10, expected_span_count=4 | ||
) | ||
self.assertEqual(4, len(spans_container.spans)) | ||
|
||
# assert root | ||
root = spans_container.get_first_root() | ||
self.assertIsNotNone(root) | ||
root_attributes = root["attributes"] | ||
self.assertEqual(root_attributes["http.status_code"], 200) | ||
# assert root | ||
root = spans_container.get_first_root() | ||
self.assertIsNotNone(root) | ||
root_attributes = root["attributes"] | ||
self.assertEqual(root_attributes["http.status_code"], 200) | ||
|
||
self.assert_attribute_length(root_attributes, 1) | ||
self.assert_attribute_length(root_attributes, 1) | ||
|
||
# assert child spans | ||
children = spans_container.get_non_internal_children() | ||
self.assertEqual(1, len(children)) | ||
child_attributes = children[0]["attributes"] | ||
self.assert_attribute_length(child_attributes, 1) | ||
# assert child spans | ||
children = spans_container.get_non_internal_children() | ||
self.assertEqual(1, len(children)) | ||
child_attributes = children[0]["attributes"] | ||
self.assert_attribute_length(child_attributes, 1) | ||
|
||
def assert_attribute_length(self, child_attributes: dict, length: int) -> None: | ||
for k, v in child_attributes.items(): | ||
if isinstance(v, str): | ||
assert len(v) == length | ||
assert len(v) == length |
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 |
---|---|---|
@@ -1,34 +1,43 @@ | ||
import unittest | ||
from test.test_utils.span_exporter import wait_for_exporter | ||
from test.test_utils.spans_parser import SpansContainer | ||
|
||
import requests | ||
|
||
from .app_runner import FastApiSample | ||
|
||
|
||
class TestExecutionTags(unittest.TestCase): | ||
def test_execution_tag(self): | ||
response = requests.get("http://localhost:8020/invoke-request") | ||
response.raise_for_status() | ||
|
||
body = response.json() | ||
|
||
assert body is not None | ||
|
||
wait_for_exporter() | ||
|
||
spans_container = SpansContainer.get_spans_from_file() | ||
self.assertEqual(4, len(spans_container.spans)) | ||
|
||
# assert root | ||
root = spans_container.get_first_root() | ||
self.assertIsNotNone(root) | ||
root_attributes = root["attributes"] | ||
self.assertEqual( | ||
type(root_attributes["lumigo.execution_tags.response_len"]), int | ||
) | ||
self.assertEqual(type(root_attributes["lumigo.execution_tags.response"]), str) | ||
self.assertEqual(root_attributes["lumigo.execution_tags.app"], True) | ||
self.assertEqual( | ||
root_attributes["lumigo.execution_tags.app.response"], "success" | ||
) | ||
self.assertEqual(root_attributes["lumigo.execution_tags.foo"], ["bar", "baz"]) | ||
with FastApiSample(): | ||
response = requests.get("http://localhost:8020/invoke-request") | ||
response.raise_for_status() | ||
|
||
body = response.json() | ||
|
||
assert body is not None | ||
|
||
spans_container = SpansContainer.get_spans_from_file( | ||
wait_time_sec=10, expected_span_count=4 | ||
) | ||
self.assertEqual(4, len(spans_container.spans)) | ||
|
||
# assert root | ||
root = spans_container.get_first_root() | ||
self.assertIsNotNone(root) | ||
root_attributes = root["attributes"] | ||
self.assertEqual( | ||
type(root_attributes["lumigo.execution_tags.response_len"]), int | ||
) | ||
self.assertEqual( | ||
type(root_attributes["lumigo.execution_tags.response"]), str | ||
) | ||
self.assertEqual(root_attributes["lumigo.execution_tags.app"], True) | ||
self.assertEqual( | ||
root_attributes["lumigo.execution_tags.app.response"], "success" | ||
) | ||
self.assertEqual( | ||
root_attributes["lumigo.execution_tags.foo"], ["bar", "baz"] | ||
) | ||
self.assertEqual( | ||
root_attributes["lumigo.execution_tags.foo"], ["bar", "baz"] | ||
) |
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,47 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from test.test_utils.processes import kill_process | ||
|
||
|
||
class FastApiSample(object): | ||
def __init__(self): | ||
cwd = Path(__file__).parent.parent | ||
print(f"cwd = {cwd}") | ||
env = { | ||
**os.environ, | ||
"AUTOWRAPT_BOOTSTRAP": "lumigo_opentelemetry", | ||
"LUMIGO_DEBUG_SPANDUMP": os.environ["LUMIGO_DEBUG_SPANDUMP"], | ||
"OTEL_SERVICE_NAME": "fastapi_test_app", | ||
} | ||
print(f"env = {env}") | ||
venv_bin_path = Path(sys.executable).parent | ||
print(f"venv_bin_path = {venv_bin_path}") | ||
cmd = f". {venv_bin_path}/activate; uvicorn app:app --port 8000" | ||
print(f"cmd = {cmd}") | ||
self.process = subprocess.Popen( | ||
cmd, | ||
cwd=cwd, | ||
env=env, | ||
shell=True, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
is_app_running = False | ||
for line in self.process.stderr: | ||
if "Uvicorn running" in str(line): | ||
print(f"FastApiSample app: {line}") | ||
is_app_running = True | ||
break | ||
print(line) | ||
if not is_app_running: | ||
raise Exception("FastApiSample app failed to start") | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __exit__(self, *args): | ||
# because we need a shell to run uvicorn we need to kill multiple processs, | ||
# but not the process group because that includes the test process as well | ||
kill_process("uvicorn") |
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