azotel

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MIT Imports: 7 Imported by: 1

README

Azure OpenTelemetry Adapter Module for Go

PkgGoDev Build Status

The azotel module is used to connect an instance of OpenTelemetry's TracerProvider to an Azure SDK client.

Getting started

NOTE: this module requires Go 1.19 or later

This project uses Go modules for versioning and dependency management.

To add the latest version to your go.mod file, execute the following command.

go get github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel

General documentation and examples can be found on pkg.go.dev.

Using the adapter

Once you have created an OpenTelemetry TracerProvider, you connect it to an Azure SDK client via its ClientOptions.

options := azcore.ClientOptions{}
options.TracingProvider = azotel.NewTracingProvider(otelProvider, nil)

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Documentation

Overview

azotel adapts OpenTelemetry tracing for consumption by the azcore/tracing package.

Example (JaegerExporter)
package main

import (
	"context"
	"log"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
	"github.com/Azure/azure-sdk-for-go/sdk/tracing/azotel"
	"go.opentelemetry.io/otel/exporters/jaeger"
	"go.opentelemetry.io/otel/sdk/resource"

	otelsdk "go.opentelemetry.io/otel/sdk/trace"

	semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)

func main() {
	// end-to-end example creating an OTel TracerProvider that exports to Jaeger
	// then uses the azotel adapter to conenct it to an Azure SDK client.

	// create the Jaeger exporter
	exp, err := jaeger.New(jaeger.WithCollectorEndpoint())
	if err != nil {
		log.Fatal(err)
	}

	// create an OTel TracerProvider that uses the Jaeger exporter
	otelTP := otelsdk.NewTracerProvider(
		otelsdk.WithBatcher(exp),
		otelsdk.WithResource(resource.NewWithAttributes(
			semconv.SchemaURL,
			semconv.ServiceNameKey.String("Example_jaegerExporter"),
		)),
	)

	// create a credential for the Azure SDK client
	credential, err := azidentity.NewDefaultAzureCredential(nil)
	if err != nil {
		log.Fatal(err)
	}

	// create an Azure SDK client, connecting the OTel TracerProvider to it
	client, err := armresources.NewClientFactory("<subscription ID>", credential, &arm.ClientOptions{
		ClientOptions: azcore.ClientOptions{
			TracingProvider: azotel.NewTracingProvider(otelTP, nil),
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	// make various API calls with the client.  each one will create its own span
	_, err = client.NewClient().CheckExistenceByID(context.TODO(), "<resource ID>", "<api-version>", nil)
	if err != nil {
		log.Fatal(err)
	}

	// shut down the tracing provider to flush all spans to Jaeger
	if err = otelTP.Shutdown(context.TODO()); err != nil {
		log.Fatal(err)
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTracingProvider

func NewTracingProvider(tracerProvider trace.TracerProvider, opts *TracingProviderOptions) tracing.Provider

NewTracingProvider creates a new tracing.Provider that wraps the specified OpenTelemetry TracerProvider.

  • tracerProvider - the TracerProvider to wrap
  • opts - optional configuration. pass nil to accept the default values

Types

type TracingProviderOptions

type TracingProviderOptions struct {
}

TracingProviderOptions contains the optional values for NewTracingProvider.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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