ditointernet / go-dito

MIT License
6 stars 0 forks source link

[trace package] - Made possible to specify Trace Exporter #38

Closed lucasmls closed 2 years ago

lucasmls commented 3 years ago

Change overview

In Trace package, right now we are forced to use GCP exporter, which is fine for Dito use case. But, thinking that go-dito is an open source project, i don't think this package should be locked in with GCP.

This pull request aims to make possible to the user of the package specify which exporter he wants to use.

How to test

You can create a simple Go project that instantiates go-dito trace package, specifying another exporter or no.

Example using Jaeger exporter

func main() {
    ctx := context.Background()

    jaegerExporter, err := jaegerTrace.NewRawExporter(
        jaegerTrace.WithCollectorEndpoint(jaegerTrace.WithEndpoint("http://localhost:14268/api/traces")),
    )
    if err != nil {
        panic(err)
    }

    tracer, flush := trace.MustNewTracer(trace.Params{
        IsProductionEnvironment: true,
        ApplicationName:         "app-name",
        TraceRatio:              1,
        Exporter:                jaegerExporter,
    })

    defer func() { _ = flush(ctx) }()
}

Example using the GCP default exporter

func main() {
    ctx := context.Background()

    tracer, flush := trace.MustNewTracer(trace.Params{
        IsProductionEnvironment: true,
        ApplicationName:         "app-name",
        TraceRatio:              1,
    })

    defer func() { _ = flush(ctx) }()
}

Deploy impacts

There is none! I kept the GCP exporter as default if no other exporter is provided. None system that uses this package should be impacted.

Disclaimer

Like we discussed in the meetings, everyone should feel free to discuss the idea or implementation of this pull request, and even don't approving it if the change is not relevant to the project!

Thanks!