Documentation
¶
Overview ¶
Package otelmongo instruments go.mongodb.org/mongo-driver/mongo.
This package is compatable with v0.2.0 of go.mongodb.org/mongo-driver/mongo.
`NewMonitor` will return an event.CommandMonitor which is used to trace requests.
This code was originally based on the following: - https://github.com/DataDog/dd-trace-go/tree/02f0449efa3cb382d499fadc873957385dcb2192/contrib/go.mongodb.org/mongo-driver/mongo - https://github.com/DataDog/dd-trace-go/tree/v1.23.3/ddtrace/ext
Example ¶
package main import ( "context" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo" ) func main() { // connect to MongoDB opts := options.Client() opts.Monitor = otelmongo.NewMonitor() opts.ApplyURI("mongodb://localhost:27017") client, err := mongo.Connect(context.Background(), opts) if err != nil { panic(err) } db := client.Database("example") inventory := db.Collection("inventory") _, err = inventory.InsertOne(context.Background(), bson.D{ {Key: "item", Value: "canvas"}, {Key: "qty", Value: 100}, {Key: "attributes", Value: bson.A{"cotton"}}, {Key: "size", Value: bson.D{ {Key: "h", Value: 28}, {Key: "w", Value: 35.5}, {Key: "uom", Value: "cm"}, }}, }) if err != nil { panic(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
const ScopeName = "go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
ScopeName is the instrumentation scope name.
Variables ¶
This section is empty.
Functions ¶
func NewMonitor ¶
func NewMonitor(opts ...Option) *event.CommandMonitor
NewMonitor creates a new mongodb event CommandMonitor.
func SemVersion
deprecated
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies instrumentation configuration options.
func WithCommandAttributeDisabled ¶
WithCommandAttributeDisabled specifies if the MongoDB command is added as an attribute to Spans or not. This is disabled by default and the MongoDB command will not be added as an attribute to Spans if this option is not provided.
func WithMarshaller ¶
func WithMarshaller(marshaller StatementMarshaller) Option
WithMarshaller sets the marshalled in chargee of managing the bson command that will be marshalled into the db.statement attribute
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
WithTracerProvider specifies a tracer provider to use for creating a tracer. If none is specified, the global provider is used.
type StatementMarshaller ¶
StatementMarshaller is an interface that implements the method to marshal the raw bson command into the db.statement attribute. It can add othe attributes if needed
func NewDefaultStatementMarshaller ¶
func NewDefaultStatementMarshaller() StatementMarshaller
NewDefaultStatementMarshaller implements StatementMarshaller. WARNING: This implementation marshals the whole db statement without any sanitization or size limit and could lead to leaks of sensitive information and performance issues in the collector.
func NewLimitedStatementMarshaller ¶
func NewLimitedStatementMarshaller(limit int) StatementMarshaller
NewLimitedStatementMarshaller creates a new limitedStatementMarshaller, that limits the size of the db.statement to the specified size. WARNING: This marshaller doesn't perform any sanitization of the statement and could leak sensitive information