apex

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 10 Imported by: 1

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

Field Source Default
Operation Id Span Trace Id
Parent Id Span Parent Id
Event Time Span Start Time
Name Span Name
Role Span Resource Service Name "unknown-service"

Requests

Field Source Default
Operation Id Span Trace Id
Parent Id Span Parent Id
Event Time Span Start Time
Name Span Name
Id Span Id
Duration Span End-Start Time
Success Span Status
Role Span Resource Service Name "unknown-service"
Url Span "url" Attribute ""
ResponseCode Span "responseCode" Attribute ""

Events

Field Source Default
Operation Id Span Trace Id
Parent Id Span Parent Id
Event Time Span Start Time
Name Span Name
Id Span Id
Duration Span End-Start Time
Success Span Status
Role Span Resource Service Name "unknown-service"
Url Span "key" Attribute ""
ResponseCode Span "responseCode" Attribute ""

Dependencies

Field Source Default
Operation Id Span Trace Id
Parent Id Span Parent Id
Event Time Span Start Time
Name Span Name
Id Span Id
Duration Span End-Start Time
Success Span Status
Role Span "source" Attribute "unknown-service"
Type Span "type" Attribute ""
Target Span Resource Service Name "unknown-target"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppInsightsExporter

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

func NewExporter

func NewExporter(
	instrumentationKey string,
	logger func(msg string) error,
) (*AppInsightsExporter, error)

NewExporter creates a new App Insights Exporter with an app insights telemetry client created from an instrumentation key. The exporter uses a logger function provided as a callback for logging events.

func (*AppInsightsExporter) ExportSpans

func (exp *AppInsightsExporter) ExportSpans(
	ctx context.Context,
	spans []sdktrace.ReadOnlySpan,
) error

ExportSpans processes and dispatches an array of Open Telemetry spans to Application Insights.

func (*AppInsightsExporter) Shutdown

func (exp *AppInsightsExporter) Shutdown(
	ctx context.Context,
) error

Shutdown closes the exporter and waits until the pending messages are sent with up to one minute grace period, or until the context is canceled. Grace period might change in the future to be optionable

Jump to

Keyboard shortcuts

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