Categorygithub.com/Soreing/apex
repositorypackage
0.4.1
Repository: https://github.com/soreing/apex.git
Documentation: pkg.go.dev

# README

AppInsights Exporter

Build Coverage Go Report Card Go Reference

Apex is a basic Open Telemetry span exporter to Azure App Insights, wrapped around the official SDK.

Usage

Create an apex exporter that you can assign to tracers. You need an instrumentation key and a hook function to handle status messages from the AppInsights SDK.

instrKey := "12345678-1234-1234-1234-1234567890ab"
exp, err := apex.NewExporter(
	instrKey,
	func(msg string) error {
		fmt.Println(msg)
		return nil
	},
)

Submit a slice of Open Telemetry ReadOnlySpan objects to the exporter and they will be processed to extract key details before they are sent to the AppInsights SDK. Spans are typically created by the Open Telemetry SDK through using tracers.

spans := /* Slice of Read Only Spans*/
err := exp.ExportSpans(context.TODO(), spans)
if err != nil {
	panic(err)
}

To stop using the exporter, use the Shutdown method. The exporter will wait on the AppInsights SDK to submit its traces, and retry for up to a minute, or until the context is canceled. The shutdown function is typically called by the Open Telemetry SDK.

err := exp.Shutdown(context.TODO())
if err != nil {
	panic(err)
}

Trace Attributes

The exporter automatically extracts information from the ReadOnlySpan objects to construct AppInsights traces. Some fields have default values that can be overridden with attributes on the ReadOnlySpan.

Internal Events

FieldSourceDefault
Operation IdSpan Trace Id
Parent IdSpan Parent Id
Event TimeSpan Start Time
NameSpan Name
RoleSpan Resource Service Name"unknown-service"

Requests

FieldSourceDefault
Operation IdSpan Trace Id
Parent IdSpan Parent Id
Event TimeSpan Start Time
NameSpan Name
IdSpan Id
DurationSpan End-Start Time
SuccessSpan Status
RoleSpan Resource Service Name"unknown-service"
UrlSpan "url" Attribute""
ResponseCodeSpan "responseCode" Attribute""

Events

FieldSourceDefault
Operation IdSpan Trace Id
Parent IdSpan Parent Id
Event TimeSpan Start Time
NameSpan Name
IdSpan Id
DurationSpan End-Start Time
SuccessSpan Status
RoleSpan Resource Service Name"unknown-service"
UrlSpan "key" Attribute""
ResponseCodeSpan "responseCode" Attribute""

Dependencies

FieldSourceDefault
Operation IdSpan Trace Id
Parent IdSpan Parent Id
Event TimeSpan Start Time
NameSpan Name
IdSpan Id
DurationSpan End-Start Time
SuccessSpan Status
RoleSpan "source" Attribute"unknown-service"
TypeSpan "type" Attribute""
TargetSpan Resource Service Name"unknown-target"