Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
add opentelemetry tracing
Browse files Browse the repository at this point in the history
exporter jaeger
exporter otel

Signed-off-by: Melchior Moulin <[email protected]>
  • Loading branch information
melchiormoulin committed Jul 3, 2022
1 parent c384da6 commit 4131487
Show file tree
Hide file tree
Showing 7 changed files with 438 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ The configuration file described in more detail the next section.
| `STATUS_TIME_WINDOW_MS` | It defines the sliding time window size (in ms) in which status information are sampled. | `300000` | |
| `DYNAMIC_CONFIG_FILE` | Location of an optional external config file that provides configuration at runtime. | empty | |
| `DYNAMIC_CONFIG_WATCHER_INTERVAL` | Interval that dynamic config file is examined for changes in content (in ms) | `30000` | |
| `EXPORTER_TYPE_TRACING` | Tracing Exporter use. Empty value disable tracing, other possible values are `jaeger` or `otlp` | `` | |


## Dynamic Configuration file
Expand Down
50 changes: 50 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
package main

import (
"context"
"flag"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
"io"
"log"
"os"
Expand Down Expand Up @@ -35,9 +43,42 @@ var (
}, nil)
)


func initTracerProvider(exporterType string) *sdktrace.TracerProvider {
resources, _ := resource.New(context.Background(),
resource.WithFromEnv(), // pull attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME environment variables
resource.WithProcess(), // This option configures a set of Detectors that discover process information
)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}))
if exporterType != "" {
exporter := exporterTracing(exporterType)
tp := sdktrace.NewTracerProvider(
sdktrace.WithResource(resources),
sdktrace.WithBatcher(exporter),
)
otel.SetTracerProvider(tp)
return tp

}
otel.SetTracerProvider(trace.NewNoopTracerProvider())
return nil
}

func exporterTracing(exporterType string) sdktrace.SpanExporter {
//Could not use OTEL_TRACES_EXPORTER https://github.com/open-telemetry/opentelemetry-go/issues/2310
var exporter sdktrace.SpanExporter
//If the env variables needed are defined we set the exporter to Jaeger else it is an opentelemetry exporter
if exporterType == "jaeger" {
exporter, _ = jaeger.New(jaeger.WithAgentEndpoint()) //from env variable https://github.com/open-telemetry/opentelemetry-go/tree/main/exporters/jaeger#environment-variables
} else if exporterType == "otlp" {
exporter, _ = otlptracegrpc.New(context.Background()) //from env variable https://github.com/open-telemetry/opentelemetry-go/blob/main/exporters/otlp/otlptrace/README.md
}
return exporter
}
var saramaLogger = log.New(io.Discard, "[Sarama] ", log.Ldate | log.Lmicroseconds)

func main() {

// get canary configuration
canaryConfig := config.NewCanaryConfig()

Expand All @@ -51,6 +92,14 @@ func main() {

glog.Infof("Starting Strimzi canary tool [%s] with config: %+v", version, canaryConfig)

tp := initTracerProvider(canaryConfig.ExporterTypeTracing)
defer func() {
if tp != nil {
if err := tp.Shutdown(context.Background()); err != nil {
log.Printf("Error shutting down tracer provider: %v", err)
}
}
}()
dynamicConfigWatcher, err := config.NewDynamicConfigWatcher(canaryConfig, applyDynamicConfig, config.NewDynamicCanaryConfig)
if err != nil {
glog.Fatalf("Failed to create dynamic config watcher: %v", err)
Expand Down Expand Up @@ -156,5 +205,6 @@ func applyDynamicConfig(dynamicCanaryConfig *config.DynamicCanaryConfig) {
} else {
saramaLogger.SetOutput(io.Discard)
}

glog.Warningf("Applied dynamic config %s", dynamicCanaryConfig)
}
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ go 1.13

require (
github.com/Shopify/sarama v1.34.0
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/glog v1.0.0
github.com/prometheus/client_golang v1.8.0
github.com/xdg-go/scram v1.1.1
go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.32.0
go.opentelemetry.io/otel v1.7.0
go.opentelemetry.io/otel/exporters/jaeger v1.7.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.7.0
go.opentelemetry.io/otel/sdk v1.7.0
go.opentelemetry.io/otel/trace v1.7.0
)
Loading

0 comments on commit 4131487

Please sign in to comment.