otelmongo

package module
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2020 License: Apache-2.0 Imports: 10 Imported by: 124

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("test-service")
	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

View Source
const (
	DBApplicationKey = label.Key("db.application")
	DBNameKey        = label.Key("db.name")
	DBSystemKey      = label.Key("db.system")
	DBInstanceKey    = label.Key("db.instance")
	DBUserKey        = label.Key("db.user")
	DBStatementKey   = label.Key("db.statement")
)
View Source
const (
	// PeerHostname records the host name of the peer.
	PeerHostnameKey = label.Key("peer.hostname")
	// PeerPort records the port number of the peer.
	PeerPortKey = label.Key("peer.port")
)
View Source
const (
	TargetHostKey  = label.Key("out.host")
	TargetPortKey  = label.Key("out.port")
	ServiceNameKey = label.Key("service.name")
	DBOperationKey = label.Key("db.operation")
	ErrorKey       = label.Key("error")
	ErrorMsgKey    = label.Key("error.msg")
)

Variables

This section is empty.

Functions

func DBApplication

func DBApplication(dbApplication string) label.KeyValue

DBApplication indicates the application using the database.

func DBInstance

func DBInstance(dbInstance string) label.KeyValue

DBInstance indicates the instance name of Database.

func DBName

func DBName(dbName string) label.KeyValue

DBName indicates the database name.

func DBOperation

func DBOperation(operation string) label.KeyValue

DBOperation defines the name of the operation.

func DBStatement

func DBStatement(dbStatement string) label.KeyValue

DBStatement records a database statement for the given database type.

func DBSystem

func DBSystem(dbType string) label.KeyValue

DBSystem indicates the system of Database.

func DBUser

func DBUser(dbUser string) label.KeyValue

DBUser indicates the user name of Database, e.g. "readonly_user" or "reporting_user".

func Error

func Error(err bool) label.KeyValue

Error specifies whether an error occurred.

func ErrorMsg

func ErrorMsg(errorMsg string) label.KeyValue

ErrorMsg specifies the error message.

func NewMonitor

func NewMonitor(serviceName string, opts ...Option) *event.CommandMonitor

NewMonitor creates a new mongodb event CommandMonitor.

func PeerHostname

func PeerHostname(peerHostname string) label.KeyValue

PeerHostname records the host name of the peer.

func PeerPort

func PeerPort(peerport string) label.KeyValue

PeerPort records the port number of the peer.

func ServiceName

func ServiceName(serviceName string) label.KeyValue

ServiceName defines the Service name for this Span.

func TargetHost

func TargetHost(targetHost string) label.KeyValue

TargetHost sets the target host address.

func TargetPort

func TargetPort(targetPort string) label.KeyValue

TargetPort sets the target host port.

Types

type Option

type Option func(*config)

Option specifies instrumentation configuration options.

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.

Directories

Path Synopsis
test module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL