-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Prasad Mujumdar <[email protected]>
- Loading branch information
1 parent
e321ef9
commit 7f128a4
Showing
5 changed files
with
74 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Dict, Any | ||
import os, warnings | ||
from importlib import import_module | ||
from opentelemetry.sdk.trace.export import SpanExporter, ConsoleSpanExporter | ||
from monocle_apptrace.exporters.file_exporter import FileSpanExporter | ||
|
||
monocle_exporters:Dict[str, Any] = { | ||
"s3": {"module": "monocle_apptrace.exporters.aws.s3_exporter", "class": "S3SpanExporter"}, | ||
"blob": {"module":"monocle_apptrace.exporters.azure.blob_exporter", "class": "AzureBlobSpanExporter"}, | ||
"okahu": {"module":"monocle_apptrace.exporters.okahu.okahu_exporter", "class": "OkahuSpanExporter"}, | ||
"file": {"module":"monocle_apptrace.exporters.file_exporter", "class": "FileSpanExporter"} | ||
} | ||
|
||
def get_monocle_exporter() -> SpanExporter: | ||
exporter_name = os.environ.get("MONOCLE_EXPORTER", "file") | ||
try: | ||
exporter_class_path = monocle_exporters[exporter_name] | ||
except Exception as ex: | ||
warnings.warn(f"Unsupported Monocle span exporter setting {exporter_name}, using default FileSpanExporter.") | ||
return FileSpanExporter() | ||
try: | ||
exporter_module = import_module(exporter_class_path.get("module")) | ||
exporter_class = getattr(exporter_module, exporter_class_path.get("class")) | ||
return exporter_class() | ||
except Exception as ex: | ||
warnings.warn(f"Unable to set Monocle span exporter to {exporter_name}, error {ex}. Using ConsoleSpanExporter") | ||
return ConsoleSpanExporter() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"span_types" : [ | ||
{ | ||
"type": "inference", | ||
"description": "Model inference span" | ||
}, | ||
{ | ||
"type": "retrieval", | ||
"description": "vector embedding retrieval" | ||
}, | ||
{ | ||
"type": "workflow", | ||
"description": "workflow orchetraction at top level" | ||
} | ||
] | ||
} |
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,27 @@ | ||
import os | ||
import unittest | ||
|
||
from monocle_apptrace.exporters.monocle_exporters import get_monocle_exporter | ||
|
||
class TestHandler(unittest.TestCase): | ||
def test_default_exporter(self): | ||
default_exporter = get_monocle_exporter() | ||
assert default_exporter.__class__.__name__ == "FileSpanExporter" | ||
|
||
def test_fallback_exporter(self): | ||
""" No Okahu API key, it should fall back to console exporter""" | ||
os.environ["MONOCLE_EXPORTER"] = "okahu" | ||
default_exporter = get_monocle_exporter() | ||
assert default_exporter.__class__.__name__ == "ConsoleSpanExporter" | ||
|
||
def test_set_exporter(self): | ||
os.environ["MONOCLE_EXPORTER"] = "okahu" | ||
os.environ["OKAHU_API_KEY"] = "foo" | ||
default_exporter = get_monocle_exporter() | ||
assert default_exporter.__class__.__name__ == "OkahuSpanExporter" | ||
|
||
if __name__ == "__main__": | ||
handler = TestHandler() | ||
handler.test_default_exporter() | ||
handler.test_fallback_exporter() | ||
handler.test_set_exporter() |