11// Copyright 2026 The go-github AUTHORS. All rights reserved.
2-
2+ //
33// Use of this source code is governed by a BSD-style
4-
54// license that can be found in the LICENSE file.
65
76// Package main provides examples for OpenTelemetry instrumentation.
8-
97package main
108
119import (
@@ -14,81 +12,54 @@ import (
1412 "log"
1513 "net/http"
1614
17- "github.com/google/go-github/v82/github"
18- "github.com/google/go-github/v82/otel"
1915 "go.opentelemetry.io/otel/exporters/stdout/stdouttrace"
2016 "go.opentelemetry.io/otel/sdk/trace"
17+
18+ "github.com/google/go-github/v82/github"
19+ "github.com/google/go-github/v82/otel"
2120)
2221
2322func main () {
24-
2523 // Initialize stdout exporter to see traces in console
26-
2724 exporter , err := stdouttrace .New (stdouttrace .WithPrettyPrint ())
28-
2925 if err != nil {
30-
3126 log .Fatalf ("failed to initialize stdouttrace exporter: %v" , err )
32-
3327 }
3428
3529 tp := trace .NewTracerProvider (
36-
3730 trace .WithBatcher (exporter ),
3831 )
3932
4033 defer func () {
41-
4234 if err := tp .Shutdown (context .Background ()); err != nil {
43-
4435 log .Fatal (err )
45-
4636 }
47-
4837 }()
4938
5039 // Configure HTTP client with OTel transport
51-
5240 httpClient := & http.Client {
53-
5441 Transport : otel .NewTransport (
55-
5642 http .DefaultTransport ,
57-
5843 otel .WithTracerProvider (tp ),
5944 ),
6045 }
6146
6247 // Create GitHub client
63-
6448 client := github .NewClient (httpClient )
6549
6650 // Make a request (Get Rate Limits is public and cheap)
67-
6851 limits , resp , err := client .RateLimit .Get (context .Background ())
69-
7052 if err != nil {
71-
7253 log .Printf ("Error fetching rate limits: %v" , err )
73-
7454 } else {
75-
7655 fmt .Printf ("Core Rate Limit: %v/%v (Resets at %v)\n " ,
77-
7856 limits .GetCore ().Remaining ,
79-
8057 limits .GetCore ().Limit ,
81-
82- limits .GetCore ().Reset )
83-
58+ limits .GetCore ().Reset ,
59+ )
8460 }
8561
86- // Check if we captured attributes in response
87-
8862 if resp != nil {
89-
90- fmt .Printf ("Response Status: %v\n " , resp .Status )
91-
63+ fmt .Printf ("Request ID: %v\n " , resp .Header .Get (github .HeaderGitHubRequestID ))
9264 }
93-
9465}
0 commit comments