@@ -41,12 +41,12 @@ ensure all spans are exported. This service makes that call as part of a
41
41
deferred function in main
42
42
43
43
``` go
44
- tp := initTracerProvider ()
45
- defer func () {
46
- if err := tp.Shutdown (context.Background ()); err != nil {
47
- log.Printf (" Error shutting down tracer provider: %v " , err)
48
- }
49
- }()
44
+ tp := initTracerProvider ()
45
+ defer func () {
46
+ if err := tp.Shutdown (context.Background ()); err != nil {
47
+ log.Printf (" Error shutting down tracer provider: %v " , err)
48
+ }
49
+ }()
50
50
```
51
51
52
52
### Adding gRPC auto-instrumentation
@@ -55,10 +55,10 @@ This service receives gRPC requests, which are instrumented in the main function
55
55
as part of the gRPC server creation.
56
56
57
57
``` go
58
- var srv = grpc.NewServer (
59
- grpc.UnaryInterceptor (otelgrpc.UnaryServerInterceptor ()),
60
- grpc.StreamInterceptor (otelgrpc.StreamServerInterceptor ()),
61
- )
58
+ var srv = grpc.NewServer (
59
+ grpc.UnaryInterceptor (otelgrpc.UnaryServerInterceptor ()),
60
+ grpc.StreamInterceptor (otelgrpc.StreamServerInterceptor ()),
61
+ )
62
62
```
63
63
64
64
This service will issue several outgoing gRPC calls, which are all instrumented
@@ -81,12 +81,12 @@ be in turn be processed by other microservices. To instrument the Kafka client
81
81
the Producer has to be wrapped after it has been created.
82
82
83
83
``` go
84
- saramaConfig := sarama.NewConfig ()
85
- producer , err := sarama.NewAsyncProducer (brokers, saramaConfig)
86
- if err != nil {
87
- return nil , err
88
- }
89
- producer = otelsarama.WrapAsyncProducer (saramaConfig, producer)
84
+ saramaConfig := sarama.NewConfig ()
85
+ producer , err := sarama.NewAsyncProducer (brokers, saramaConfig)
86
+ if err != nil {
87
+ return nil , err
88
+ }
89
+ producer = otelsarama.WrapAsyncProducer (saramaConfig, producer)
90
90
```
91
91
92
92
### Add attributes to auto-instrumented spans
@@ -95,19 +95,19 @@ Within the execution of auto-instrumented code you can get current span from
95
95
context.
96
96
97
97
``` go
98
- span := trace.SpanFromContext (ctx)
98
+ span := trace.SpanFromContext (ctx)
99
99
```
100
100
101
101
Adding attributes to a span is accomplished using ` SetAttributes ` on the span
102
102
object. In the ` PlaceOrder ` function several attributes are added to the span.
103
103
104
104
``` go
105
- span.SetAttributes (
106
- attribute.String (" app.order.id" , orderID.String ()), shippingTrackingAttribute,
107
- attribute.Float64 (" app.shipping.amount" , shippingCostFloat),
108
- attribute.Float64 (" app.order.amount" , totalPriceFloat),
109
- attribute.Int (" app.order.items.count" , len (prep.orderItems )),
110
- )
105
+ span.SetAttributes (
106
+ attribute.String (" app.order.id" , orderID.String ()), shippingTrackingAttribute,
107
+ attribute.Float64 (" app.shipping.amount" , shippingCostFloat),
108
+ attribute.Float64 (" app.order.amount" , totalPriceFloat),
109
+ attribute.Int (" app.order.items.count" , len (prep.orderItems )),
110
+ )
111
111
```
112
112
113
113
### Add span events
@@ -119,14 +119,14 @@ attributes, others do not.
119
119
Adding a span event without attributes:
120
120
121
121
``` go
122
- span.AddEvent (" prepared" )
122
+ span.AddEvent (" prepared" )
123
123
```
124
124
125
125
Adding a span event with additional attributes:
126
126
127
127
``` go
128
- span.AddEvent (" charged" ,
129
- trace.WithAttributes (attribute.String (" app.payment.transaction.id" , txID)))
128
+ span.AddEvent (" charged" ,
129
+ trace.WithAttributes (attribute.String (" app.payment.transaction.id" , txID)))
130
130
```
131
131
132
132
## Metrics
@@ -156,23 +156,23 @@ ensure all records are exported. This service makes that call as part of a
156
156
deferred function in main
157
157
158
158
``` go
159
- mp := initMeterProvider ()
160
- defer func () {
161
- if err := mp.Shutdown (context.Background ()); err != nil {
162
- log.Printf (" Error shutting down meter provider: %v " , err)
163
- }
164
- }()
159
+ mp := initMeterProvider ()
160
+ defer func () {
161
+ if err := mp.Shutdown (context.Background ()); err != nil {
162
+ log.Printf (" Error shutting down meter provider: %v " , err)
163
+ }
164
+ }()
165
165
```
166
166
167
167
### Adding golang runtime auto-instrumentation
168
168
169
169
Golang runtime are instrumented in the main function
170
170
171
171
``` go
172
- err := runtime.Start (runtime.WithMinimumReadMemStatsInterval (time.Second ))
173
- if err != nil {
174
- log.Fatal (err)
175
- }
172
+ err := runtime.Start (runtime.WithMinimumReadMemStatsInterval (time.Second ))
173
+ if err != nil {
174
+ log.Fatal (err)
175
+ }
176
176
```
177
177
178
178
## Logs
0 commit comments