Debian Codegraph @

instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/example_test.go

raw symbols SCIP
1 // Copyright The OpenTelemetry Authors
2 // SPDX-License-Identifier: Apache-2.0
3
4 package otelmongo_test
5
6 import (
7 "context"
8
9 "go.mongodb.org/mongo-driver/bson"
10 "go.mongodb.org/mongo-driver/mongo"
11 "go.mongodb.org/mongo-driver/mongo/options"
12
13 "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
14 )
15
16 func Example() {
17 // connect to MongoDB
18 opts := options.Client()
19 opts.Monitor = otelmongo.NewMonitor()
20 opts.ApplyURI("mongodb://localhost:27017")
21 client, err := mongo.Connect(context.Background(), opts)
22 if err != nil {
23 panic(err)
24 }
25 db := client.Database("example")
26 inventory := db.Collection("inventory")
27
28 _, err = inventory.InsertOne(context.Background(), bson.D{
29 {Key: "item", Value: "canvas"},
30 {Key: "qty", Value: 100},
31 {Key: "attributes", Value: bson.A{"cotton"}},
32 {Key: "size", Value: bson.D{
33 {Key: "h", Value: 28},
34 {Key: "w", Value: 35.5},
35 {Key: "uom", Value: "cm"},
36 }},
37 })
38 if err != nil {
39 panic(err)
40 }
41 }