Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split components module #203

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ smoke-sdk-http: smoke-tests/collector/data.json

smoke-sdk: smoke-sdk-grpc smoke-sdk-http

smoke-distroless-grpc: smoke-tests/collector/data.json
@echo ""
@echo "+++ Running gRPC smoke tests."
@echo ""
cd smoke-tests && bats ./smoke-distroless-grpc.bats --report-formatter junit --output ./

smoke-distroless: smoke-distroless-grpc

smoke: docker_compose_present
@echo ""
@echo "+++ Smoking all the tests."
Expand Down
4 changes: 0 additions & 4 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,3 @@ const (
classicKeyMissingDatasetMessage string = "Honeycomb Classic API Key detected!\nYour API key: %s requires a dataset to be configured.\nConfigure via HONEYCOMB_DATASET or in code."
dontSetADatasetMessageMessage string = "Dataset detected! Datasets are a Honeycomb Classic configuration value.\nUnset HONEYCOMB_DATASET or remove configuration code that sets a dataset."
)

func isClassicApiKey(apiKey string) bool {
return len(apiKey) == 32
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package honeycomb
package components

import (
"context"
Expand All @@ -26,7 +26,7 @@ type baggageSpanProcessor struct{}

var _ trace.SpanProcessor = (*baggageSpanProcessor)(nil)

// Returns a new baggageSpanProcessor.
// NewBaggageSpanProcessor returns a new baggageSpanProcessor.
//
// The Baggage span processor duplicates onto a span the attributes found
// in Baggage in the parent context at the moment the span is started.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package honeycomb
package components

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package honeycomb
package components

import (
"go.opentelemetry.io/otel/attribute"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package honeycomb
package components

import (
"testing"
Expand Down
20 changes: 20 additions & 0 deletions components/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module github.com/honeycombio/honeycomb-opentelemetry-go/components

go 1.21

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/otel v1.25.0
go.opentelemetry.io/otel/sdk v1.25.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
27 changes: 27 additions & 0 deletions components/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k=
go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg=
go.opentelemetry.io/otel/metric v1.25.0 h1:LUKbS7ArpFL/I2jJHdJcqMGxkRdxpPHE0VU/D4NuEwA=
go.opentelemetry.io/otel/metric v1.25.0/go.mod h1:rkDLUSd2lC5lq2dFNrX9LGAbINP5B7WBkC78RXCpH5s=
go.opentelemetry.io/otel/sdk v1.25.0 h1:PDryEJPC8YJZQSyLY5eqLeafHtG+X7FWnf3aXMtxbqo=
go.opentelemetry.io/otel/sdk v1.25.0/go.mod h1:oFgzCM2zdsxKzz6zwpTZYLLQsFwc+K0daArPdIhuxkw=
go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM=
go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package honeycomb
package components

import (
"context"
Expand Down Expand Up @@ -111,3 +111,7 @@ func (e *spanLinkExporter) Shutdown(ctx context.Context) error {
}
return nil
}

func isClassicApiKey(apiKey string) bool {
return len(apiKey) == 32
}
30 changes: 30 additions & 0 deletions components/span_link_exporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright Honeycomb Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package components

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSpanLinkExporterBuildsValidUrl(t *testing.T) {
t.Run("classic", func(t *testing.T) {
assert.Equal(t, "https://ui.honeycomb.io/my-team/datasets/my-service/trace?trace_id", buildTraceLinkUrl(true, "my-team", "my-env", "my-service"))
})
t.Run("environment", func(t *testing.T) {
assert.Equal(t, "https://ui.honeycomb.io/my-team/environments/my-env/datasets/my-service/trace?trace_id", buildTraceLinkUrl(false, "my-team", "my-env", "my-service"))
})
}
4 changes: 2 additions & 2 deletions examples/baggage/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"time"

"github.com/honeycombio/honeycomb-opentelemetry-go"
"github.com/honeycombio/honeycomb-opentelemetry-go/components"
"github.com/honeycombio/otel-config-go/otelconfig"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/baggage"
Expand All @@ -39,7 +39,7 @@ func main() {
attribute.Int64("app.unix_time_ms", time.Now().UnixMilli()),
}
})
bsp := honeycomb.NewBaggageSpanProcessor()
bsp := components.NewBaggageSpanProcessor()

shutdown, err := otelconfig.ConfigureOpenTelemetry(
otelconfig.WithSpanProcessor(dsp, bsp),
Expand Down
14 changes: 14 additions & 0 deletions examples/distroless/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.22 AS build
WORKDIR /src
ENV CGO_ENABLED=0
COPY . .
RUN go get
RUN cd ./examples/distroless && go get && go build -o /out/distroless

FROM scratch AS bin
WORKDIR /app
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=build /out/distroless /app/
ENV OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=bogus_key"
EXPOSE 8090
ENTRYPOINT ["/app/distroless"]
108 changes: 108 additions & 0 deletions examples/distroless/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package main

import (
"context"
"fmt"
"log"
"net/http"
"os"
"strconv"
"strings"

"github.com/honeycombio/honeycomb-opentelemetry-go/components"
"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"
"go.opentelemetry.io/otel/sdk/trace"
)

// Implement an HTTP Handler function to be instrumented
func httpHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello, World")
}

// Wrap the HTTP handler function with OTel HTTP instrumentation
func wrapHandler() {
handler := http.HandlerFunc(httpHandler)
wrappedHandler := otelhttp.NewHandler(handler, "hello")
http.Handle("/hello", wrappedHandler)
}

// Running the example:
// export OTEL_SERVICE_NAME=distroless-example
// export OTEL_EXPORTER_OTLP_HEADERS="x-honeycomb-team=XXXX"
// export OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io:443
// export HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS=1
// go run example.go
func main() {
var opts []trace.TracerProviderOption
// Enable local visualizations
if enableLocalVisualizationsStr := os.Getenv("HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS"); enableLocalVisualizationsStr != "" {
var apikey, headers, serviceName string
if serviceName = os.Getenv("OTEL_SERVICE_NAME"); serviceName == "" {
serviceName = "unknown_service:go"
}

if headers = os.Getenv("OTEL_EXPORTER_OTLP_HEADERS"); headers != "" {
for _, header := range strings.Split(headers, ",") {
if strings.HasPrefix(header, "x-honeycomb-team=") {
if parts := strings.Split(header, "="); len(parts) > 1 {
apikey = parts[1]
}
}
}
}
enabled, _ := strconv.ParseBool(enableLocalVisualizationsStr)
if enabled {
exporter, _ := components.NewSpanLinkExporter(apikey, serviceName)
opts = append(opts, trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(exporter)))
}
}
// Enable multi-span attributes
opts = append(opts, trace.WithSpanProcessor(components.NewBaggageSpanProcessor()))

if sampleRateStr := os.Getenv("SAMPLE_RATE"); sampleRateStr != "" {
sampleRate, err := strconv.Atoi(sampleRateStr)
if err == nil {
opts = append(opts, trace.WithSampler(components.NewDeterministicSampler(sampleRate)))
}
}

ctx := context.Background()
// Configure a new OTLP exporter using environment variables for sending data to Honeycomb over gRPC
client := otlptracegrpc.NewClient()
exp, err := otlptrace.New(ctx, client)
if err != nil {
log.Fatalf("failed to initialize exporter: %e", err)
}
opts = append(opts, trace.WithBatcher(exp))

// Create a new tracer provider with a batch span processor and the otlp exporter
tp := trace.NewTracerProvider(opts...)

// Handle shutdown to ensure all sub processes are closed correctly and telemetry is exported
defer func() {
_ = exp.Shutdown(ctx)
_ = tp.Shutdown(ctx)
}()

// Register the global Tracer provider
otel.SetTracerProvider(tp)

// Register the W3C trace context and baggage propagators so data is propagated across services/processes
otel.SetTextMapPropagator(
propagation.NewCompositeTextMapPropagator(
propagation.TraceContext{},
propagation.Baggage{},
),
)

// Initialize HTTP handler instrumentation
wrapHandler()
port := 3030
listenAddr := fmt.Sprintf(":%d", port)
log.Printf("Now listening on:%d ....\n", port)
log.Fatal(http.ListenAndServe(listenAddr, nil))
}
50 changes: 50 additions & 0 deletions examples/distroless/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module github.com/honeycombio/honeycomb-opentelemetry-go/examples/distroless

go 1.21

require (
github.com/honeycombio/honeycomb-opentelemetry-go v0.10.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0
go.opentelemetry.io/otel v1.25.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.25.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.25.0
go.opentelemetry.io/otel/sdk v1.25.0
)

require (
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/honeycombio/otel-config-go v1.13.1 // indirect
github.com/lufia/plan9stats v0.0.0-20231016141302-07b5767bb0ed // indirect
github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect
github.com/sethvargo/go-envconfig v0.9.0 // indirect
github.com/shirou/gopsutil/v3 v3.23.10 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/host v0.46.1 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.46.1 // indirect
go.opentelemetry.io/contrib/propagators/b3 v1.21.1 // indirect
go.opentelemetry.io/contrib/propagators/ot v1.21.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.23.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.25.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading
Loading