Skip to content

Conversation

@Samriddha9619
Copy link

@Samriddha9619 Samriddha9619 commented Dec 4, 2025

Which problem is this PR solving?

Description of the changes

  • Added a new configuration flag -marshal-to-file to internal/tracegen/config.go.
  • Updated cmd/tracegen/main.go to intercept the exporter creation logic.
  • When the flag is set, the OTel stdout exporter is initialized with a custom os.File writer instead of the default os.Stdout.
  • This allows separating the JSON span data (written to file) from application logs (written to console), ensuring the output is valid JSON suitable for replay.
  • Implemented proper shutdown ordering: ensuring the TracerProvider flushes all spans to the exporter before the file handle is closed.

How was this change tested?

  • Manual Verification:
    • Ran command: ./tracegen -marshal-to-file=test.json -traces=1
    • Verified test.json contains valid, clean JSON span data with no log corruption.
    • Verified application logs (INFO level) still appear in the console.
  • Lint & Test:
    • Ran golangci-lint on modified packages (passed).
    • Ran go test ./internal/tracegen/... (passed).

Checklist

@Samriddha9619 Samriddha9619 requested a review from a team as a code owner December 4, 2025 19:59
@dosubot dosubot bot added the enhancement label Dec 4, 2025
@yurishkuro
Copy link
Member

Part 1 of Resolves #xxxx

When you have text Resolves #xxxx this PR will close the issue. If it's only a partial change then say Part of #xxxx

if fileWriter != nil {
return stdouttrace.New(
stdouttrace.WithWriter(fileWriter),
stdouttrace.WithPrettyPrint(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need pretty-print for what is meant to be a machine-readable format?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I did it for debugging, but you're right, production doesn't need it

@Samriddha9619 Samriddha9619 force-pushed the feature/tracegen-file-export branch from 9dcee2c to bbb5126 Compare December 5, 2025 03:19
fs.StringVar(&c.Service, "service", "tracegen", "Service name prefix to use")
fs.IntVar(&c.Services, "services", 1, "Number of unique suffixes to add to service name when generating traces, e.g. tracegen-01 (but only one service per trace)")
fs.StringVar(&c.TraceExporter, "trace-exporter", "otlp-http", "Trace exporter (otlp/otlp-http|otlp-grpc|stdout). Exporters can be additionally configured via environment variables, see https://github.com/jaegertracing/jaeger/blob/main/cmd/tracegen/README.md")
fs.StringVar(&c.ExportToFile, "export-to-file", "", "Filename to write generated spans to (in JSON format) instead of sending to a collector")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking - adding this new option creates an ambiguity, which one takes precedence, this one or trace-exporter. We can keep it to a single flag if we allow file:{filename} syntax.

Btw the README incorrectly says the option name is -exporter, can you fix it in the same PR?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Samriddha9619 Samriddha9619 force-pushed the feature/tracegen-file-export branch from 872ebd9 to 8e7c11f Compare December 5, 2025 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants