Skip to content

Commit c7d80b1

Browse files
authored
Merge pull request #292 from Scale3-Labs/obinna/S3EN-1111-bump-version
Obinna/s3 en 1111 bump version
2 parents 6ebc5b4 + 719a7e9 commit c7d80b1

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

src/langtrace_python_sdk/extensions/langtrace_exporter.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import typing
4+
import sys
45

56
import requests
67
from opentelemetry.sdk.trace.export import ReadableSpan, SpanExporter, SpanExportResult
@@ -49,18 +50,21 @@ class LangTraceExporter(SpanExporter):
4950

5051
api_key: str
5152
api_host: str
53+
disable_logging: bool
5254

5355
def __init__(
5456
self,
5557
api_host,
5658
api_key: str = None,
59+
disable_logging: bool = False,
5760
) -> None:
5861
self.api_key = api_key or os.environ.get("LANGTRACE_API_KEY")
5962
self.api_host = (
6063
f"{LANGTRACE_REMOTE_URL}/api/trace"
6164
if api_host == LANGTRACE_REMOTE_URL
6265
else api_host
6366
)
67+
self.disable_logging = disable_logging
6468

6569
def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
6670
"""
@@ -72,7 +76,7 @@ def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
7276
Returns:
7377
The result of the export SUCCESS or FAILURE
7478
"""
75-
if not self.api_key:
79+
if not self.api_key and not self.disable_logging:
7680
print(Fore.RED)
7781
print(
7882
"Missing Langtrace API key, proceed to https://langtrace.ai to create one"
@@ -107,14 +111,15 @@ def export(self, spans: typing.Sequence[ReadableSpan]) -> SpanExportResult:
107111

108112
if not response.ok:
109113
raise RequestException(response.text)
110-
111-
print(
112-
Fore.GREEN + f"Exported {len(spans)} spans successfully." + Fore.RESET
113-
)
114+
if not self.disable_logging:
115+
print(
116+
Fore.GREEN + f"Exported {len(spans)} spans successfully." + Fore.RESET
117+
)
114118
return SpanExportResult.SUCCESS
115119
except RequestException as err:
116-
print(Fore.RED + "Failed to export spans.")
117-
print(Fore.RED + f"Error: {err}" + Fore.RESET)
120+
if not self.disable_logging:
121+
print(Fore.RED + "Failed to export spans.")
122+
print(Fore.RED + f"Error: {err}" + Fore.RESET)
118123
return SpanExportResult.FAILURE
119124

120125
def shutdown(self) -> None:

src/langtrace_python_sdk/langtrace.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ def init(
7272
disable_instrumentations: Optional[DisableInstrumentations] = None,
7373
disable_tracing_for_functions: Optional[InstrumentationMethods] = None,
7474
service_name: Optional[str] = None,
75+
disable_logging = False
7576
):
77+
if disable_logging:
78+
sys.stdout = open(os.devnull, "w")
7679

7780
host = (
7881
os.environ.get("LANGTRACE_API_HOST", None) or api_host or LANGTRACE_REMOTE_URL
@@ -90,7 +93,7 @@ def init(
9093
provider = TracerProvider(resource=resource, sampler=sampler)
9194

9295
remote_write_exporter = (
93-
LangTraceExporter(api_key=api_key, api_host=host)
96+
LangTraceExporter(api_key=api_key, api_host=host, disable_logging=disable_logging)
9497
if custom_remote_exporter is None
9598
else custom_remote_exporter
9699
)
@@ -146,6 +149,8 @@ def init(
146149
print(Fore.BLUE + "Exporting spans to Langtrace cloud.." + Fore.RESET)
147150
provider.add_span_processor(batch_processor_remote)
148151

152+
sys.stdout = sys.__stdout__
153+
149154

150155
def init_instrumentations(
151156
disable_instrumentations: DisableInstrumentations, all_instrumentations: dict
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.2.22"
1+
__version__ = "2.2.23"

0 commit comments

Comments
 (0)