Has backwards compatibility with https://github.com/night-codes/mgo-ai package.
The option to connect OpenTelemetry
is available.
AIG_MONGO_URI
type
: stringURI for connecting to MongoDB, required.
AIG_MONGO_USER
type
: stringCredentials for connecting to mongodb.
AIG_MONGO_PASSWORD
type
: stringCredentials for connecting to mongodb.
AIG_MONGO_DB
type
: stringThe name of the database where data about increment will be stored, required.
AIG_MONGO_COLLECTION
type
: stringThe name of the collection where data about increment will be stored, required.
import (
"github.com/ch1f/aig"
"go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo"
)
// Getting data from env
aigCfg := aig.GetConfigEnv()
// also you can specify them from another source
aigCfg.DB = "aig"
aigCfg.Collection = "aig"
// Connecting the mongodb trace to OpenTelemtry
aigCfg.Monitor = otelmongo.NewMonitor()
// Creating a module. If there is an error connecting to the database, panic will be used inside.
aigModule := aig.Create(ctx, aigCfg)
//So, you can start using incrementation according to method that is backward compatible with mgo-ai
someID := aigModule.Next("some")
//or use new one with tracing
someID := aigModule.Generate(ctx, "some")