monitaraexporter

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 17 Imported by: 0

README

otelmonitara-exporter


otelmonitara-exporter is a small, dependency-free library for exports opentelemetry logs to monitara APM .

Installation

$ go get github.com/hamzaabujarad/otelmonitara-exporter

Usage

//Monitara Opentelemetry end points
	hosts := []string{"YOUR_END_POINT"}
	//Monitara open telemetry apiKey
	apiKey := "YOUR_API_KEY"
	//Max documents size per task
	maxBatchSize := 100
	//debug mode on or off
	verbose := true
	//How often should new tasks be executed (in ms)
	interval := 5000
	//calling the monitara exporter
	exporter, err := monitaraexporter.New(hosts, apiKey, maxBatchSize, verbose, interval)
	if err != nil {
		return nil, err
	}

API

exporter, err := monitaraexporter.New(hosts, apiKey, maxBatchSize, verbose, interval)
Option Default Description
hosts `` Monitara Opentelemetry end points
apiKey `` Monitara open telemetry apiKey
maxBatchSize 200 Max documents size per task
interval 2000 How often should new tasks be executed (in ms)
verbose true Verbose mode

Example With Gin WebFrameWork

import (
	"net/http"

	"github.com/gin-gonic/gin"
	//monitara exporter
	monitaraexporter "github.com/hamzaabujarad/oltp-monitaraexporter"
	"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/propagation"
	"go.opentelemetry.io/otel/sdk/resource"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
	semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

func initTracer() (*sdktrace.TracerProvider, error) {
	//Monitara Opentelemetry end points
	hosts := []string{"YOUR_END_POINT"}
	//Monitara open telemetry apiKey
	apiKey := "YOUR_API_KEY"
	//Max documents size per task
	maxBatchSize := 100
	//debug mode on or off
	verbose := true
	//How often should new tasks be executed (in ms)
	interval := 5000
	//calling the monitara exporter
	exporter, err := monitaraexporter.New(hosts, apiKey, maxBatchSize, verbose, interval)
	if err != nil {
		return nil, err
	}
	// For the demonstration, use sdktrace.AlwaysSample sampler to sample all traces.
	// In a production application, use sdktrace.ProbabilitySampler with a desired probability.
	tp := sdktrace.NewTracerProvider(
		sdktrace.WithBatcher(exporter),
		sdktrace.WithResource(resource.NewWithAttributes(semconv.SchemaURL, semconv.ServiceName("YourServicesName"))),
	)
	otel.SetTracerProvider(tp)
	otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
	return tp, err
}

func main() {
	tp, _ := initTracer()
	r := gin.Default()
	otel.SetTracerProvider(tp)
	r.Use(otelgin.Middleware("todo-service")) // Your service name will be shown in tags.
	r.GET("/", func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{"data": "hello world"})
	})
	r.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetIndexNamePrefixFromApiKey

func GetIndexNamePrefixFromApiKey(apikey string)

generate Documents index

func InsertBulk

func InsertBulk(es *elasticsearch.Client, spans []CustomSpan) error

Types

type CustomSpan

type CustomSpan struct {
	ActivityId string                 `json:"activityId"`
	ParentId   *string                `json:"parentId"`
	TraceId    string                 `json:"traceId"`
	SpanId     string                 `json:"spanId"`
	SourceName string                 `json:"sourceName"`
	Status     string                 `json:"status"`
	Duration   time.Duration          `json:"duration"`
	Kind       int                    `json:"kind"`
	Timestamp  time.Time              `json:"timestamp"`
	Tags       map[string]interface{} `json:"tags"`
}

type Exporter

type Exporter struct {
	// contains filtered or unexported fields
}

Exporter is an implementation

func New

func New(hosts []string, apiKey string, maxBatchSize int, verbose bool, interval int) (*Exporter, error)

New creates an Exporter with the passed options.

func (*Exporter) ExportSpans

func (e *Exporter) ExportSpans(ctx context.Context, spans []trace.ReadOnlySpan) error

ExportSpans writes spans in custom format

func (*Exporter) Shutdown

func (e *Exporter) Shutdown(ctx context.Context) error

Shutdown is called to stop the exporter, it preforms no action.

Jump to

Keyboard shortcuts

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