Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

adamko147/opentelemetry-azure-monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠ WARNING: This repository is no longer updated.
To export tracing to Azure Monitor, consider using opentelemetry collector and azuremonitorexporter

OpenTelemetry Azure Monitor

Installation

go get github.com/adamko147/opentelemetry-azure-monitor

Usage

Trace

The Azure Monitor Span Exporter allows you to export OpenTelemetry traces to Azure Monitor.

This example shows how to send a span "hello" to Azure Monitor.

package main

import (
	"context"
	"log"

	appinsights "github.com/adamko147/opentelemetry-azure-monitor/appinsights"
	"go.opentelemetry.io/otel"
	"go.opentelemetry.io/otel/codes"
	sdktrace "go.opentelemetry.io/otel/sdk/trace"
)

func main() {
	ctx := context.Background()

	shutdown, err := appinsights.InstallNewPipeline(
		appinsights.WithProcess(appinsights.Process{
			ServiceName: "trace-demo",
		}),
		appinsights.WithInstrumentationKey("<instrumentation-key>")
		appinsights.WithOptions(
			sdktrace.WithSampler(sdktrace.AlwaysSample()),
		),
	)
	if err != nil {
		log.Fatal(err)
	}
	defer shutdown(ctx)

	tracer := otel.Tracer("my-module")
	_, span := tracer.Start(ctx, "operation")
	log.Println("Hello World")
	span.SetStatus(codes.Ok, "Succeeded")
	span.End()
}