Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OpenTelemetry as best way how to instrument you...

OpenTelemetry as best way how to instrument your CICD pipeline

OpenTelemetry as best way how to instrument your CICD pipeline

- Honeycomb buildevents
- Trace
- Equinix-labs Otel CLI
- Dagger.io manual OTEL instrumentation

video: https://www.youtube.com/watch?v=VIvvUYS7kmk

Ladislav Prskavec

September 27, 2023
Tweet

More Decks by Ladislav Prskavec

Other Decks in Technology

Transcript

  1. O en el me ry s es w y h

    w o ns ru en y ur C CD ip li e L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  2. P pe in L v P c, r S (@a

    @h r .i ) - C N #5, 2 . e 2 2
  3. D st ib te T ac ng n 30 S

    co ds 4 A span m s i r a s 4 A trace c i s L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 3
  4. { "name": "build abtris/www.prskavec.net-Build_index-136-1", "context": { "trace_id": "abtris/www.prskavec.net-Build_index-136-1", "span_id": "abtris/www.prskavec.net-Build_index-136-1"

    }, "start_time": "2022-04-29T18:52:58.114201Z", "end_time": "2022-04-29T18:52:58.114687Z", "attributes": { "ci.host": "hostname", "github.repository": "github.com/abtris/www.prskavec.net", "github.run_id": "6285578193" }, "events": [ { "name": "Hello Cloud Native!", "timestamp": "2022-04-29T18:52:58.114561Z", "attributes": { "event_attributes": 1 } } ] } L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 4
  5. A to at c s an al ns ru en

    at on 1. A i i e n w o d ’t v k n c u a t d n t r d . 2. M i e n, w o c t r t c g t n m e u h t n m o . 4 O e i n 4 A -i e n - s e .N , J , J , P , P , d m L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 5
  6. T ol ng or ns ru en at on I

    4 T 4 H m b e 4 C a G A W o O e D y P e P a t H m - g e o t a t i t 4 E -l e C 4 J O e p 4 o -d -v L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 6
  7. T ol ng or D 4 K 4 M N

    8 D e O B 4 I o d t A , F , G , k , e . p y : 4 A e A -A R m (O M ) 4 T s f d e (O T ) 4 T d e o i c (t a s ) 4 T s L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 7
  8. T ac L v P c, r S (@a @h

    r .i ) - C N #5, 2 . e 2 8
  9. T ac b A dy av es h ://g .c

    /P m/T / 4 s o G g, P l 4 r n a i s T : s r l , b b e w L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 9
  10. U ag 1. s a t export TRACEPARENT="$(trace start "some-name")

    2. s g : group=$(trace group start "some-name") 3. r p e i a g : trace task "${group}" -- some command here 4. n h g trace group finish "${group}" 5. n h t trace finish L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  11. H ne co b - b il ev nt L

    v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  12. ... jobs: build: runs-on: ubuntu-latest steps: - uses: honeycombio/gha-buildevents@v2 with:

    apikey: ${{ secrets.BUILDEVENT_APIKEY }} dataset: gha-buildevents_integration status: ${{ job.status }} - name: Check out repo uses: actions/checkout@v3 - name: Set up Go uses: actions/setup-go@v4 with: go-version-file: 'go.mod' - run: |- STEP_ID=setup-go STEP_START=$(date +%s) go version buildevents step $TRACE_ID $STEP_ID $STEP_START $STEP_ID ... 4 G l - b .y L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  13. L v P c, r S (@a @h r .i

    ) - C N #5, 2 . e 2 1
  14. T ac in b il s ep builtevents step $TRACE_ID

    $STEP_ID $STEP_START $STEP_NAME 4 $TRACE_ID - e c h c a h l w o c . i v e a i e h H m g -b e A . 4 $STEP_ID - e a u i e o c s . I ’s s a s , u a o h r c a s , i ’s s s n s i e m v e. 4 $STEP_START - A t m h f e m (s s 1 -1-1 U ). e b e c t h t d n c s . o e s i e m v e i i a r c e s h o a h e c e . 4 $STEP_NAME - A h -r e m o h s . i m l e e d i h t e e q g u t d . I ’s p e s h m v STEP_ID, h I e a h -r e w . L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  15. I cr as ng ra ul ri y n ou

    b il s ep buildevents cmd $TRACE_ID $STEP_ID $CMD_NAME -- $CMD 4 $TRACE_ID n $STEP_ID` r u e . b t h -r e n a u i e . 4 $STEP_NAME s u $CMD_NAME. m n h m e t o 4 $CMD a a w d n c s n l c e . B d , h c l e d i /bin/bash -c. 4 f e o h m L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  16. C pt ri g ve ts ro b il s

    ha f il 4 b d e a i d 't o t 4 d i h b e o h o b e c w c g . 4 F , h d b r G A o h r n w o f . - id: "Honeycomb: Finalize pact-credit-score" if: always() run: buildevents step $TRACE_ID $STEP_ID $STEP_START $STEP_ID L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  17. 4 I h e a f b s , i

    "a " s l u e n s , e t a r s u a p s f . T r , o n d n r c w c n o l n a e e t H m e h d n o a r . 4 T a t , h f n d l a u h n s , u u h e c l n h a h r t r e a u t c i - id: "Honeycomb: Finalize pact-credit-score" if: always() env: OUTCOME: ${{ steps.pact-credit-score.outcome }} run: | if echo $OUTCOME | grep -wq -e success -e failure; then buildevents step $TRACE_ID $STEP_ID $STEP_START $STEP_ID fi L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  18. D h f n c h b n c s

    u w o : 4 M c i i b e e t w n a s . 4 E n a t c p s b e u i : always(). 4 U h o h w e c o n a n s . 4 A v e h s b s $GITHUB_ENV. L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 1
  19. - id: build-special-membership run: | echo "STEP_ID=build_special-membership" >> $GITHUB_ENV echo

    "STEP_START=$(date +%s)" >> $GITHUB_ENV source $GITHUB_ENV # build buildevents cmd $TRACE_ID $STEP_ID 'build' -- \ mvn clean verify -pl special-membership-service -Pcode-coverage -Pstatic-code-analysis - name: "Honeycomb: Finalize build-special-membership" if: always() env: OUTCOME: ${{ steps.build-special-membership.outcome }} run: | if echo $OUTCOME | grep -wq -e success -e failure; then buildevents step $TRACE_ID $STEP_ID $STEP_START $STEP_ID fi L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  20. O EL LI L v P c, r S (@a

    @h r .i ) - C N #5, 2 . e 2 2
  21. O EL LI 4 e l d m u otel-cli

    server tui otel-desktop-viewer 4 s m e v (H m , L e , E ) export LIGHTSTEP_TOKEN= # Lightstep API key (otlp/1 in the yaml) export HONEYCOMB_TEAM= # Honeycomb API key (otlp/2 in the yaml) export HONEYCOMB_DATASET=playground # Honeycomb dataset export ELASTIC_TOKEN= # Elastic token for the APM server. 4 r a p i a s 4 p t c i e o a c c c s 4 f a d c o a s a a h b u , n d e i , n c l u s L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  22. S mp e xa pl otel-desktop-viewer # configure otel-cli to

    send to our desktop viewer endpoint export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 # use otel-cli to generate spans! otel-cli exec --service my-service --name "curl blog" curl https://www.prskavec.net L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  23. L v P c, r S (@a @h r .i

    ) - C N #5, 2 . e 2 2
  24. I st um nt ng y ip li e n

    ag er L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  25. O EL et p n ou c de import (

    ... "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp" "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.21.0" "go.opentelemetry.io/otel/trace" ... ) L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  26. const ( instrumentationName = "github.com/abtris/dagger-tutorial" instrumentationVersion = "0.1.0" ) var

    ( tracer = otel.GetTracerProvider().Tracer( instrumentationName, trace.WithInstrumentationVersion(instrumentationVersion), trace.WithSchemaURL(semconv.SchemaURL), ) sc trace.SpanContext ) L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  27. ctx := context.Background() opts := otlptracehttp.WithInsecure() client := otlptracehttp.NewClient(opts) exporter,

    err := otlptrace.New(ctx, client) if err != nil { fmt.Errorf("creating OTLP trace exporter: %w", err) } tracerProvider := sdktrace.NewTracerProvider( sdktrace.WithBatcher(exporter), sdktrace.WithResource(resource.Default()), ) otel.SetTracerProvider(tracerProvider) // Handle shutdown properly so nothing leaks. defer func() { _ = tracerProvider.Shutdown(ctx) }() L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  28. M nu l ns ru en at on L v

    P c, r S (@a @h r .i ) - C N #5, 2 . e 2 2
  29. 4 I span o a d e , a t

    , e func build(ctx context.Context, repoUrl string) error { ctx, span = tracer.Start(ctx, "initDagger") span.AddEvent("start init dagger") span.SetAttributes(attribute.Bool("cache", true)) client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout)) if err != nil { span.SetStatus(codes.Error, err.Error()) span.RecordError(err) return err 4 d 't f c h a span.End() b defer span.End() L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 3
  30. D mo 4 s l v o t export OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4318"

    export OTEL_TRACES_EXPORTER="otlp" export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf" otel-desktop-viewer 4 s c L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 3
  31. Q es io s? F ll w e n @a

    tr s@h ch de m.i L v P c, r S (@a @h r .i ) - C N #5, 2 . e 2 3