Skip to content

Commit

Permalink
maint: update golang/year service to be plain otel (#993)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
Updates the golang year service to use plain otel SDK.

- Closes
#968

## Short description of the changes
- Updates golang year service to use base otel SDK instead of honeycomb
otel distro
- Add missing env vars in tilt file
  • Loading branch information
MikeGoldsmith authored Mar 19, 2024
1 parent 1bd1b37 commit 5c0e745
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ def launch_go_svc(name, dirname="", flags="", auto_init=True):
'NAME_ENDPOINT': 'http://localhost:8000',
'YEAR_ENDPOINT': 'http://localhost:6001',
'MESSAGE_ENDPOINT': 'http://localhost:9000',
'OTEL_EXPORTER_OTLP_ENDPOINT': 'api.honeycomb.io:443',
'OTEL_EXPORTER_OTLP_HEADERS': 'x-honeycomb-team=' + os.environ['HONEYCOMB_API_KEY']
}
if "go" in to_run or name in to_run:
print("About to start {} with command {}".format(name, cmd))
Expand Down
27 changes: 21 additions & 6 deletions golang/year-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import (
"log"
"math/rand"
"net/http"
"os"
"time"

_ "github.com/honeycombio/honeycomb-opentelemetry-go"

"github.com/honeycombio/otel-config-go/otelconfig"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/trace"
)

Expand Down Expand Up @@ -41,11 +45,22 @@ func yearHandler(w http.ResponseWriter, r *http.Request) {
}

func main() {
otelShutdown, err := otelconfig.ConfigureOpenTelemetry()
if err != nil {
log.Fatalf("error setting up OTel SDK - %e", err)
}
defer otelShutdown()
ctx := context.Background()
exporter, _ := otlptrace.New(ctx, otlptracegrpc.NewClient(
otlptracegrpc.WithEndpoint(os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT")),
otlptracegrpc.WithHeaders(map[string]string{
"x-honeycomb-team": os.Getenv("HONEYCOMB_API_KEY"),
}),
))
tracerProvider := sdktrace.NewTracerProvider(
sdktrace.WithBatcher(exporter),
)
defer tracerProvider.Shutdown(ctx)

otel.SetTracerProvider(tracerProvider)
otel.SetTextMapPropagator(
propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}),
)

tracer = otel.Tracer("greeting-service/year-service")

Expand Down

0 comments on commit 5c0e745

Please sign in to comment.