Skip to content

Commit

Permalink
Added workflow name to default file name
Browse files Browse the repository at this point in the history
Signed-off-by: Prasad Mujumdar <[email protected]>
  • Loading branch information
prasad-okahu committed Jul 28, 2024
1 parent 60e2c17 commit cd17689
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Monocle_User_Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ chain.invoke({"number":2}, {"callbacks":[handler]})
```

### Accessing monocle trace
By default monocle generate traces in a json file created in the local directory where the application is running. The file name by default is monocle_trace_<trace_id>_<timestamp>.json where the trace_id is a unique number generated by monocle for every trace. Please refere to [Trace span json](Monocle_User_Guide.md#trace-span-json). The file path and format can be changed by setting those properties as argement to ```setup_monocle_telemetry()```. For example,
By default monocle generate traces in a json file created in the local directory where the application is running. The file name by default is monocle_trace_{workflow_name}\_{trace_id}\_{timestamp}.json where the trace_id is a unique number generated by monocle for every trace. Please refere to [Trace span json](Monocle_User_Guide.md#trace-span-json). The file path and format can be changed by setting those properties as argement to ```setup_monocle_telemetry()```. For example,
```
setup_monocle_telemetry(workflow_name = "simple_math_app",
span_processors=[BatchSpanProcessor(FileSpanExporter(
Expand Down
10 changes: 6 additions & 4 deletions src/monocle_apptrace/exporters/file_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Optional, Callable, Sequence
from opentelemetry.sdk.trace import ReadableSpan
from opentelemetry.sdk.trace.export import SpanExporter, SpanExportResult
from opentelemetry.sdk.resources import SERVICE_NAME, Resource

class FileSpanExporter(SpanExporter):
DEFAULT_FILE_PREFIX:str = "monocle_trace_"
Expand Down Expand Up @@ -32,16 +33,17 @@ def __init__(
def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
for span in spans:
if span.context.trace_id != self.current_trace_id:
self.rotate_file(span.context.trace_id)
self.rotate_file(span.resource.attributes[SERVICE_NAME],
span.context.trace_id)
self.out_handle.write(self.formatter(span))
self.out_handle.flush()
return SpanExportResult.SUCCESS

def rotate_file(self, trace_id:int) -> None:
def rotate_file(self, trace_name:str, trace_id:int) -> None:
self.reset_handle()
self.current_file_path = path.join(self.output_path,
self.file_prefix + hex(trace_id) + "_" +
datetime.now().strftime(self.time_format) + ".json")
self.file_prefix + trace_name + "_" + hex(trace_id) + "_"
+ datetime.now().strftime(self.time_format) + ".json")
self.out_handle = open(self.current_file_path, "w")
self.current_trace_id = trace_id

Expand Down

0 comments on commit cd17689

Please sign in to comment.