-
Notifications
You must be signed in to change notification settings - Fork 585
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
Add github.com/gofiber/fiber trace instrumentation #880
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
fa1eb2a
add gofiber support
WLun001 34c7b50
update example
WLun001 ad5cb65
Apply suggestions from code review
WLun001 a935b9a
apply suggestions
WLun001 e07589d
apply suggestions for test file
WLun001 908d912
remove readme
WLun001 dd8d2ce
Update CHANGELOG.md
WLun001 c420aef
remove unreachable if block
WLun001 058b488
Update CHANGELOG.md
WLun001 0febf4d
update comment and headers construction
WLun001 797e9fd
add new module to dependabot
WLun001 c9d7935
Apply suggestions from code review
WLun001 831878b
go mod tidy and go fmt
WLun001 f7a72e4
Merge branch 'main' into fiber
WLun001 92aa894
add recordError, update sdk to RC3
WLun001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
instrumentation/github.com/gofiber/fiber/otelfiber/config.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright The OpenTelemetry 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 otelfiber | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/propagation" | ||
oteltrace "go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
// config is used to configure the Fiber middleware. | ||
type config struct { | ||
TracerProvider oteltrace.TracerProvider | ||
Propagators propagation.TextMapPropagator | ||
} | ||
|
||
// Option specifies instrumentation configuration options. | ||
type Option interface { | ||
apply(*config) | ||
} | ||
|
||
type optionFunc func(*config) | ||
|
||
func (o optionFunc) apply(c *config) { | ||
o(c) | ||
} | ||
|
||
// WithPropagators specifies propagators to use for extracting | ||
// information from the HTTP requests. If none are specified, global | ||
// ones will be used. | ||
func WithPropagators(propagators propagation.TextMapPropagator) Option { | ||
return optionFunc(func(cfg *config) { | ||
cfg.Propagators = propagators | ||
}) | ||
} | ||
|
||
// WithTracerProvider specifies a tracer provider to use for creating a tracer. | ||
// If none is specified, the global provider is used. | ||
func WithTracerProvider(provider oteltrace.TracerProvider) Option { | ||
return optionFunc(func(cfg *config) { | ||
cfg.TracerProvider = provider | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright The OpenTelemetry 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 otelfiber instruments the github.com/gofiber/fiber package. | ||
// (https://github.com/gofiber/fiber). | ||
// | ||
// Currently only the routing of a received message can be instrumented. To do | ||
// so, use the Middleware function. | ||
package otelfiber // import "go.opentelemetry.io/contrib/instrumentation/github.com/gofiber/fiber/otelfiber" |
20 changes: 20 additions & 0 deletions
20
instrumentation/github.com/gofiber/fiber/otelfiber/example/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright The OpenTelemetry 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. | ||
FROM golang:alpine AS base | ||
COPY . /src/ | ||
WORKDIR /src/instrumentation/github.com/gofiber/fiber/otelefiber/example | ||
|
||
FROM base AS fiber-server | ||
RUN go install ./server.go | ||
CMD ["/go/bin/server"] |
28 changes: 28 additions & 0 deletions
28
instrumentation/github.com/gofiber/fiber/otelfiber/example/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# gofiber fiber instrumentation example | ||
|
||
An HTTP server using gofiber fiber and instrumentation. The server has a | ||
`/users/:id` endpoint. The server generates span information to | ||
`stdout`. | ||
|
||
These instructions expect you have | ||
[docker-compose](https://docs.docker.com/compose/) installed. | ||
|
||
Bring up the `fiber-server` and `fiber-client` services to run the | ||
example: | ||
|
||
```sh | ||
docker-compose up --detach fiber-server fiber-client | ||
``` | ||
|
||
The `fiber-client` service sends just one HTTP request to `fiber-server` | ||
and then exits. View the span generated by `fiber-server` in the logs: | ||
|
||
```sh | ||
docker-compose logs fiber-server | ||
``` | ||
|
||
Shut down the services when you are finished with the example: | ||
|
||
```sh | ||
docker-compose down | ||
``` |
39 changes: 39 additions & 0 deletions
39
instrumentation/github.com/gofiber/fiber/otelfiber/example/docker-compose.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright The OpenTelemetry 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. | ||
version: "3.7" | ||
services: | ||
fiber-client: | ||
image: golang:alpine | ||
networks: | ||
- example | ||
command: | ||
- "/bin/sh" | ||
- "-c" | ||
- "wget http://fiber-server:3000/users/123 && cat 123" | ||
depends_on: | ||
- fiber-server | ||
fiber-server: | ||
build: | ||
dockerfile: $PWD/Dockerfile | ||
context: ../../../../../../ | ||
ports: | ||
- "3000:80" | ||
command: | ||
- "/bin/sh" | ||
- "-c" | ||
- "/go/bin/server" | ||
networks: | ||
- example | ||
networks: | ||
example: |
22 changes: 22 additions & 0 deletions
22
instrumentation/github.com/gofiber/fiber/otelfiber/example/go.mod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module go.opentelemetry.io/opentelemetry-go-contrib/instrumentation/github.com/gofiber/fiber/otelfiber/example | ||
|
||
go 1.15 | ||
|
||
replace ( | ||
go.opentelemetry.io/contrib => ../../../../../../ | ||
go.opentelemetry.io/contrib/instrumentation/github.com/gofiber/fiber/otelfiber => ../ | ||
go.opentelemetry.io/contrib/propagators/b3 => ../../../../../../propagators/b3 | ||
|
||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gofiber/fiber/v2 v2.14.0 | ||
github.com/klauspost/compress v1.13.1 // indirect | ||
go.opentelemetry.io/contrib/instrumentation/github.com/gofiber/fiber/otelfiber v0.23.0 | ||
go.opentelemetry.io/otel v1.0.0-RC3 | ||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.0.0-RC3 | ||
go.opentelemetry.io/otel/sdk v1.0.0-RC3 | ||
go.opentelemetry.io/otel/trace v1.0.0-RC3 | ||
|
||
) |
54 changes: 54 additions & 0 deletions
54
instrumentation/github.com/gofiber/fiber/otelfiber/example/go.sum
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
github.com/andybalholm/brotli v1.0.2 h1:JKnhI/XQ75uFBTiuzXpzFrUriDPiZjlOSzh6wXogP0E= | ||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
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/gofiber/fiber/v2 v2.14.0 h1:oAUxouH4RWBE9r/3aZbucFefjdMmDF8rUsAIbyWkctY= | ||
github.com/gofiber/fiber/v2 v2.14.0/go.mod h1:oZTLWqYnqpMMuF922SjGbsYZsdpE1MCfh416HNdweIM= | ||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | ||
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= | ||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= | ||
github.com/klauspost/compress v1.13.1 h1:wXr2uRxZTJXHLly6qhJabee5JqIhTRoLBhDOA74hDEQ= | ||
github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= | ||
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/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= | ||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= | ||
github.com/valyala/fasthttp v1.26.0 h1:k5Tooi31zPG/g8yS6o2RffRO2C9B9Kah9SY8j/S7058= | ||
github.com/valyala/fasthttp v1.26.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA= | ||
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= | ||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= | ||
go.opentelemetry.io/otel v1.0.0-RC1/go.mod h1:x9tRa9HK4hSSq7jf2TKbqFbtt58/TGk0f9XiEYISI1I= | ||
go.opentelemetry.io/otel v1.0.0-RC3 h1:kvwiyEkiUT/JaadXzVLI/R1wDO934A7r3Bs2wEe6wqA= | ||
go.opentelemetry.io/otel v1.0.0-RC3/go.mod h1:Ka5j3ua8tZs4Rkq4Ex3hwgBgOchyPVq5S6P2lz//nKQ= | ||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.0.0-RC3 h1:ewSzc2SagdOx0up5xZPigXh1n3SLsNEslc5edHRBVcs= | ||
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.0.0-RC3/go.mod h1:Oxmrmpdvm6lM3tkYmHKGWAhi9+9c2rrAEbwSDn0Bvv8= | ||
go.opentelemetry.io/otel/oteltest v1.0.0-RC1 h1:G685iP3XiskCwk/z0eIabL55XUl2gk0cljhGk9sB0Yk= | ||
go.opentelemetry.io/otel/oteltest v1.0.0-RC1/go.mod h1:+eoIG0gdEOaPNftuy1YScLr1Gb4mL/9lpDkZ0JjMRq4= | ||
go.opentelemetry.io/otel/sdk v1.0.0-RC3 h1:iRMkET+EmJUn5mW0hJzygBraXRmrUwzbOtNvTCh/oKs= | ||
go.opentelemetry.io/otel/sdk v1.0.0-RC3/go.mod h1:78H6hyg2fka0NYT9fqGuFLvly2yCxiBXDJAgLKo/2Us= | ||
go.opentelemetry.io/otel/trace v1.0.0-RC1/go.mod h1:86UHmyHWFEtWjfWPSbu0+d0Pf9Q6e1U+3ViBOc+NXAg= | ||
go.opentelemetry.io/otel/trace v1.0.0-RC3 h1:9F0ayEvlxv8BmNmPbU005WK7hC+7KbOazCPZjNa1yME= | ||
go.opentelemetry.io/otel/trace v1.0.0-RC3/go.mod h1:VUt2TUYd8S2/ZRX09ZDFZQwn2RqfMB5MzO17jBojGxo= | ||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015 h1:hZR0X1kPW+nwyJ9xRxqZk1vx5RUObAPBdKVvXPDUH/E= | ||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
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.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
80 changes: 80 additions & 0 deletions
80
instrumentation/github.com/gofiber/fiber/otelfiber/example/server.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright The OpenTelemetry 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 main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"log" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
|
||
"go.opentelemetry.io/contrib/instrumentation/github.com/gofiber/fiber/otelfiber" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
stdout "go.opentelemetry.io/otel/exporters/stdout/stdouttrace" | ||
"go.opentelemetry.io/otel/propagation" | ||
sdktrace "go.opentelemetry.io/otel/sdk/trace" | ||
oteltrace "go.opentelemetry.io/otel/trace" | ||
) | ||
|
||
var tracer = otel.Tracer("fiber-server") | ||
|
||
func main() { | ||
tp := initTracer() | ||
defer func() { | ||
if err := tp.Shutdown(context.Background()); err != nil { | ||
log.Printf("Error shutting down tracer provider: %v", err) | ||
} | ||
}() | ||
|
||
app := fiber.New() | ||
app.Use(otelfiber.Middleware("my-server")) | ||
|
||
app.Get("/", func(ctx *fiber.Ctx) error { | ||
return errors.New("abc") | ||
}) | ||
|
||
app.Get("/users/:id", func(c *fiber.Ctx) error { | ||
id := c.Params("id") | ||
name := getUser(c.UserContext(), id) | ||
return c.JSON(fiber.Map{"id": id, name: name}) | ||
}) | ||
|
||
log.Fatal(app.Listen(":3000")) | ||
} | ||
|
||
func initTracer() *sdktrace.TracerProvider { | ||
exporter, err := stdout.New(stdout.WithPrettyPrint()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
tp := sdktrace.NewTracerProvider( | ||
sdktrace.WithSampler(sdktrace.AlwaysSample()), | ||
sdktrace.WithBatcher(exporter), | ||
) | ||
otel.SetTracerProvider(tp) | ||
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) | ||
return tp | ||
} | ||
|
||
func getUser(ctx context.Context, id string) string { | ||
_, span := tracer.Start(ctx, "getUser", oteltrace.WithAttributes(attribute.String("id", id))) | ||
defer span.End() | ||
if id == "123" { | ||
return "otelfiber tester" | ||
} | ||
return "unknown" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@open-telemetry/go-approvers Would it be better to recommend:
sdktrace.WithResource(resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceNameKey.String("fiber-server"))),
tosdktrace.NewTracerProvider
callgetUser
usingoteltrace.SpanFromContext()
?
Reference: https://github.com/open-telemetry/opentelemetry-go-contrib/blob/main/instrumentation/net/http/otelhttp/example/server/server.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A service name should definitely be provided in the resource given to the tracer provider initialization.