1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-14 10:13:10 +02:00
opentelemetry-go/example/otlp
David C Wang ce49579d66 Fixed OTLP example's accidental early close of exporter
* The exp.Stop() as argument to handleErr is getting executed
  immediately.  Wrap this with an anonymous func so that this
  argument is executed when the defer statement is activated.
* From the "Tour of Go" docs on Defer: "The deferred call's arguments
  are evaluated immediately, but the function call is not executed
  until the surrounding function returns."
2020-06-09 20:36:17 +00:00
..
example-otlp-config.yaml Finish OTLP example 2020-05-27 10:06:33 -05:00
go.mod Add replace directive to example go.mod 2020-06-02 14:31:30 -05:00
go.sum Run precommit 2020-06-04 08:29:10 -07:00
main.go Fixed OTLP example's accidental early close of exporter 2020-06-09 20:36:17 +00:00
README.md Fix go.mod dependencies 2020-06-02 14:11:23 -05:00

OTLP Example

This example demonstrates how to export trace and metric data from an application using OpenTelemetry's own wire protocol OTLP. We will also walk you through configuring a collector to accept OTLP exports.

How to run?

Prequisites

  • go >=1.13 installed
  • OpenTelemetry collector is available

Configure the Collector

Follow the instructions on the website to install a working instance of the collector. This example assumes you have the collector installed locally.

To configure the collector to accept OTLP traffic from our application, ensure that it has the following configs:

receivers:
    otlp:
        endpoint: 0.0.0.0:55680   # listens to localhost:55680

    # potentially other receivers

service:
    pipelines:

        traces:
            receivers:
                - otlp
                # potentially other receivers
            processors: # whatever processors you need
            exporters: # wherever you want your data to go

        metrics:
            receivers:
                -otlp
                # potentially other receivers
            processors: etc
            exporters: etc

    # other services

An example config has been provided at example-otlp-config.yaml.

Then to run:

./[YOUR_COLLECTOR_BINARY]  --config [PATH_TO_CONFIG]

If you use the example config, it's set to export to stdout. If you run the collector on the same machine as the example application, you should see trace and metric outputs from the collector.

Start the Application

An example application is included in this directory. It simulates the process of scribing a spell scroll (e.g. in D&D). The application has been instrumented and exports both trace and metric data via OTLP to any listening receiver. To run it:

go get -d go.opentelemetry.io/otel
cd $GOPATH/go.opentelemetry.io/otel/example/otlp
go run main.go

The application is currently configured to transmit exported data to localhost:55680. See main.go for full details.

After starting the application, you should see trace and metric log output on the collector.

Note, if the receiver is incorrectly configured to take in metric data, the application may complain about being unable to connect.