Skip to content

Commit db317fc

Browse files
SubmarineepellaredMrAlias
authored
Verify and update OTLP trace exporter documentation (#2053)
* Inventory the documentation for and examples of the OTLP exporter. * modify the documentation for otlptrace exporter. * Update exporters/otlp/otlptrace/README.md Co-authored-by: Robert Pająk <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Robert Pająk <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * add otlptrace example_test.go * modify the documentation for otlptrace exporter. * modify the documentation for otlptrace exporter. * Update exporters/otlp/otlptrace/example_test.go Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/example_test.go Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/example_test.go Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Robert Pająk <[email protected]> * modify the documentation for otlptrace exporter. * Update exporters/otlp/otlptrace/README.md Co-authored-by: Robert Pająk <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Robert Pająk <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Robert Pająk <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * Update exporters/otlp/otlptrace/README.md Co-authored-by: Tyler Yahn <[email protected]> * Move example to otlptracehttp package * Unexport example functions * Fix markdownlint errors * Specify payload types in README Co-authored-by: Robert Pająk <[email protected]> Co-authored-by: Tyler Yahn <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent 04de34a commit db317fc

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

exporters/otlp/otlptrace/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# OpenTelemetry-Go OTLP Span Exporter
2+
3+
[![Go Reference](https://pkg.go.dev/badge/go.opentelemetry.io/otel/exporters/otlp/otlptrace.svg)](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace)
4+
5+
[OpenTelemetry Protocol Exporter](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.5.0/specification/protocol/exporter.md) implementation.
6+
7+
## Installation
8+
9+
```
10+
go get -u go.opentelemetry.io/otel/exporters/otlp/otlptrace
11+
```
12+
13+
## Examples
14+
15+
- [Exporter setup and examples](./otlptracehttp/example_test.go)
16+
- [Full example sending telemetry to a local collector](../../../example/otel-collector)
17+
18+
## [`otlptrace`](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace)
19+
20+
The `otlptrace` package provides an exporter implementing the OTel span exporter interface.
21+
This exporter is configured using a client satisfying the `otlptrace.Client` interface.
22+
This client handles the transformation of data into wire format and the transmission of that data to the collector.
23+
24+
## [`otlptracegrpc`](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc)
25+
26+
The `otlptracegrpc` package implements a client for the span exporter that sends trace telemetry data to the collector using gRPC with protobuf-encoded payloads.
27+
28+
## [`otlptracehttp`](https://pkg.go.dev/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp)
29+
30+
The `otlptracehttp` package implements a client for the span exporter that sends trace telemetry data to the collector using HTTP with protobuf-encoded payloads.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package otlptracehttp_test
16+
17+
import (
18+
"context"
19+
"log"
20+
21+
"go.opentelemetry.io/otel"
22+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
23+
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
24+
"go.opentelemetry.io/otel/sdk/resource"
25+
sdktrace "go.opentelemetry.io/otel/sdk/trace"
26+
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
27+
"go.opentelemetry.io/otel/trace"
28+
)
29+
30+
const (
31+
instrumentationName = "github.com/instrumentron"
32+
instrumentationVersion = "v0.1.0"
33+
)
34+
35+
var (
36+
tracer = otel.GetTracerProvider().Tracer(
37+
instrumentationName,
38+
trace.WithInstrumentationVersion(instrumentationVersion),
39+
trace.WithSchemaURL(semconv.SchemaURL),
40+
)
41+
)
42+
43+
func add(ctx context.Context, x, y int64) int64 {
44+
var span trace.Span
45+
_, span = tracer.Start(ctx, "Addition")
46+
defer span.End()
47+
48+
return x + y
49+
}
50+
51+
func multiply(ctx context.Context, x, y int64) int64 {
52+
var span trace.Span
53+
_, span = tracer.Start(ctx, "Multiplication")
54+
defer span.End()
55+
56+
return x * y
57+
}
58+
59+
func newResource() *resource.Resource {
60+
return resource.NewWithAttributes(
61+
semconv.SchemaURL,
62+
semconv.ServiceNameKey.String("otlptrace-example"),
63+
semconv.ServiceVersionKey.String("0.0.1"),
64+
)
65+
}
66+
67+
func installExportPipeline(ctx context.Context) func() {
68+
client := otlptracehttp.NewClient()
69+
exporter, err := otlptrace.New(ctx, client)
70+
if err != nil {
71+
log.Fatalf("creating OTLP trace exporter: %v", err)
72+
}
73+
74+
tracerProvider := sdktrace.NewTracerProvider(
75+
sdktrace.WithBatcher(exporter),
76+
sdktrace.WithResource(newResource()),
77+
)
78+
otel.SetTracerProvider(tracerProvider)
79+
80+
return func() {
81+
if err := tracerProvider.Shutdown(ctx); err != nil {
82+
log.Fatalf("stopping tracer provider: %v", err)
83+
}
84+
}
85+
}
86+
87+
func Example() {
88+
ctx := context.Background()
89+
// Registers a tracer Provider globally.
90+
cleanup := installExportPipeline(ctx)
91+
defer cleanup()
92+
93+
log.Println("the answer is", add(ctx, multiply(ctx, multiply(ctx, 2, 2), 10), 2))
94+
}

exporters/otlp/otlptrace/otlptracehttp/go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ go 1.15
44

55
require (
66
github.com/stretchr/testify v1.7.0
7+
go.opentelemetry.io/otel v1.0.0-RC2
78
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.0.0-RC2
9+
go.opentelemetry.io/otel/sdk v1.0.0-RC2
10+
go.opentelemetry.io/otel/trace v1.0.0-RC2
811
go.opentelemetry.io/proto/otlp v0.9.0
912
google.golang.org/protobuf v1.27.1
1013
)

0 commit comments

Comments
 (0)