Skip to content

Commit 959dcd8

Browse files
committed
typecast safety example
1 parent 380e1ee commit 959dcd8

File tree

1 file changed

+8
-4
lines changed
  • docs/platforms/go/common/tracing/instrumentation/custom-instrumentation

1 file changed

+8
-4
lines changed

docs/platforms/go/common/tracing/instrumentation/custom-instrumentation/index.mdx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,16 @@ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
7171
Or you can update existing transaction and span data by:
7272

7373
```go
74-
if d := transaction.Data["dataAttr1"]; d != nil {
75-
transaction.SetData("dataAttr1", d.(int)+42)
74+
if d, found := transaction.Data["dataAttr1"]; found {
75+
if dataAttr1, ok := d.(int); ok {
76+
transaction.SetData("dataAttr1", dataAttr1.(int)+42)
77+
}
7678
}
7779

78-
if d := span.Data["dataAttr1"]; d != nil {
79-
span.SetData("dataAttr1", d.(int)+42)
80+
if d, found := span.Data["dataAttr1"]; found {
81+
if dataAttr1, ok := d.(int); ok {
82+
span.SetData("dataAttr1", dataAttr1.(int)+42)
83+
}
8084
}
8185
})
8286
```

0 commit comments

Comments
 (0)