Skip to content

Commit 7f18127

Browse files
authored
Edit the SDK documentation for new sample apps (#529)
* Edit the SDK docs * Add meterprovider to disclaimer * Rename files to be more generic * Address comments on PR * Add metrics to title
1 parent da25ec8 commit 7f18127

File tree

9 files changed

+148
-39
lines changed

9 files changed

+148
-39
lines changed

src/docs/getting-started/go-sdk.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ In this tutorial, we will introduce how to use OpenTelemetry Go SDK for manual i
1616

1717
## Getting Started
1818

19-
* [Manual Instrumentation for Traces with OpenTelemetry Go SDK](/docs/getting-started/go-sdk/trace-manual-instr)
19+
* [Manual Instrumentation for Traces and Metrics with OpenTelemetry Go SDK](/docs/getting-started/go-sdk/manual-instr)
2020

2121

2222
## Sample Code
2323

24-
* [AWS Distro for OpenTelemetry Sample Code with Go SDK](https://github.com/aws-observability/aws-otel-go/tree/main/sampleapp)
24+
* [AWS Distro for OpenTelemetry Sample Code with Go SDK](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/go-sample-app)

src/docs/getting-started/go-sdk/trace-manual-instr.mdx renamed to src/docs/getting-started/go-sdk/manual-instr.mdx

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: 'Tracing with the AWS Distro for OpenTelemetry Go SDK and X-Ray'
2+
title: 'Using the AWS Distro for OpenTelemetry Go SDK'
33
description:
44
OpenTelemetry provides different language SDKs to instrument code for collecting telemetry data in the application.
5-
In this tutorial, we will introduce how to use OpenTelemetry Go SDK for traces instrumentation in the application.
6-
path: '/docs/getting-started/go-sdk/trace-manual-instr'
5+
In this tutorial, we will introduce how to use OpenTelemetry Go SDK for traces and metrics instrumentation in the application.
6+
path: '/docs/getting-started/go-sdk/manual-instr'
77
---
88

99
import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
@@ -19,19 +19,19 @@ import goImg6 from "assets/img/docs/gettingStarted/goSDK/img6.jpg"
1919

2020
## Introduction
2121
Welcome to the AWS Distro for OpenTelemetry (ADOT) Go getting started guide. This walk-through covers the ADOT Go components, how to
22-
configure the ADOT components to capture traces with OpenTelemetry Go and AWS X-Ray, as well as how to use the AWS Elastic Container Service
22+
configure the ADOT components to capture traces and metrics with OpenTelemetry Go, as well as how to use the AWS Elastic Container Service
2323
(AWS ECS) and AWS Elastic Kubernetes Service (AWS EKS) resource detectors. Before reading this guide, you should familiarize with
24-
distributed tracing and the basics of OpenTelemetry. To learn more about getting started with OpenTelemetry Go, see the
24+
distributed tracing/metrics and the basics of OpenTelemetry. To learn more about getting started with OpenTelemetry Go, see the
2525
[OpenTelemetry developer documentation](https://opentelemetry.io/docs/go/).
2626

2727
<img src={goImg1} alt="Diagram" style="margin: 30px 0;" />
2828

2929
<SectionSeparator />
3030

3131
## Requirements
32-
Go `v1.15` or later is required to run an application using OpenTelemetry. Visit the [compatibility chart](https://github.com/open-telemetry/opentelemetry-go#compatibility) of OpenTelemetry Go SDK with different `OS`, `Go Version` and `Architecture`.
32+
Go `v1.19` or later is required to run an application using OpenTelemetry. Visit the [compatibility chart](https://github.com/open-telemetry/opentelemetry-go#compatibility) of OpenTelemetry Go SDK with different `OS`, `Go Version` and `Architecture`.
3333

34-
Note: You’ll also need to have the [ADOT Collector](https://aws-otel.github.io/docs/getting-started/collector) running to export traces to X-Ray.
34+
Note: You’ll also need to have the [ADOT Collector](https://aws-otel.github.io/docs/getting-started/collector) running to export traces and metrics.
3535

3636
<SectionSeparator />
3737

@@ -44,6 +44,9 @@ Download and install the following packages to use ADOT Components with OpenTele
4444
3. OTel Go SDK for tracing
4545
4. OTel Go API for tracing
4646
5. OTLP gRPC exporter for exporting trace data
47+
6. OTel Go SDK for metrics
48+
7. OTel Go API for metrics
49+
8. OTLP gRPC exporter for exporting metric data
4750
```
4851

4952
To install the above mentioned necessary prerequisites, run the following command in the same directory that the application `go.mod` file is in:
@@ -53,13 +56,15 @@ go get go.opentelemetry.io/otel
5356
go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc
5457
go get go.opentelemetry.io/otel/sdk/resource
5558
go get go.opentelemetry.io/otel/sdk/trace
59+
go get go.opentelemetry.io/otel/sdk/metric
60+
go get go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc
5661
```
5762

5863
<SectionSeparator />
5964

6065
## Setting up the Global Tracer
6166

62-
### Sending Traces to AWS X-Ray
67+
### Sending Traces
6368

6469
This section talks about how to instantiate a new tracer provider with the X-Ray ID generator and sampling config, setting global options (X-Ray propagator, tracer provider) and instantiate OTLP exporter with the collector's address to export trace data.
6570

@@ -70,10 +75,9 @@ This section talks about how to instantiate a new tracer provider with the X-Ray
7075
OpenTelemetry Go requires an exporter to send traces to a backend. Exporters allow telemetry data to be transferred either to the AWS Distro for OpenTelemetry Collector (ADOT Collector), or to a remote system or console for further analysis. The ADOT Collector is a separate process that is designed to be a "sink" for telemetry data emitted by many processes, which can then export
7176
that data to various back-end systems.
7277

73-
To initialize the OTLP exporter, add the following code to the file the `main.go` file.
78+
To initialize the OTLP trace exporter, add the following code to the file the `main.go` file.
7479

75-
76-
**IMPORTANT**: The following example creates an OTLP exporter that does not encrypt data at transfer because it uses the `otlptracegrpc.WithInsecure()` option. This should only be used for creating proof of concepts and experimenting with the Go SDK.
80+
**IMPORTANT**: The following examples creates an OTLP exporter that does not encrypt data at transfer because it uses the `otlptracegrpc.WithInsecure()` option. This should only be used for creating proof of concepts and experimenting with the Go SDK.
7781
For production environments you must properly configure TLS using the `otlptracegrpc.WithTLSCredentials` function.
7882

7983
```go lineNumbers=true
@@ -135,6 +139,48 @@ tracerProvider := trace.NewTracerProvider(
135139
trace.WithResource(resource),
136140
)
137141
```
142+
## Setting up the Global Meter
143+
144+
### Sending metrics
145+
146+
This section talks about how to instantiate a new meter provider , setting global options (meter provider) and instantiate OTLP exporter with the collector's address to export metric data.
147+
148+
#### Creating an OpenTelemetry Protocol (OTLP) Exporter
149+
150+
OpenTelemetry Go requires an exporter to send metrics to a backend. Exporters allow telemetry data to be transferred either to the AWS Distro for OpenTelemetry Collector (ADOT Collector), or to a remote system or console for further analysis. The ADOT Collector is a separate process that is designed to be a "sink" for telemetry data emitted by many processes, which can then export
151+
that data to various back-end systems.
152+
153+
To initialize the OTLP metric exporter, add the following code to the file the `main.go` file.
154+
155+
**IMPORTANT**: The following examples creates an OTLP exporter that does not encrypt data at transfer because it uses the `otlpmetricgrpc.WithInsecure()` option. This should only be used for creating proof of concepts and experimenting with the Go SDK.
156+
For production environments you must properly configure TLS using the `otlpmetricgrpc.WithTLSCredentials` function.
157+
158+
```go lineNumbers=true
159+
// Create and start new OTLP metric exporter
160+
metricExporter, err := otlpmetricgrpc.New(ctx, otlpmetricgrpc.WithInsecure(), otlpmetricgrpc.WithEndpoint("0.0.0.0:4317"), otlpmetricgrpc.WithDialOption(grpc.WithBlock()))
161+
if err != nil {
162+
log.Fatalf("failed to create new OTLP metric exporter: %v", err)
163+
}
164+
```
165+
166+
#### Creating a Meter Provider
167+
168+
In order to generate metrics, OpenTelemetry Go SDK requires a meter provider to be created. The meter provider is configured with a periodic reader in this example.
169+
170+
To create a new meter provider, add the following lines to the `main.go` file.
171+
```go lineNumbers=true
172+
mp := metric.NewMeterProvider(metric.WithReader(metric.NewPeriodicReader(metricExporter))
173+
```
174+
175+
Above block of code creates a new `MeterProvider` with a periodic reader.
176+
177+
178+
#### Setting Global Options
179+
180+
To set up global options for the meter provider, we will use the `otel` package and add the following line to the `main.go` file.
181+
```go lineNumbers=true
182+
otel.SetMeterProvider(mp)
183+
```
138184

139185
<SubSectionSeparator />
140186

@@ -256,7 +302,27 @@ _, span := tracer.Start(
256302
defer span.End()
257303
```
258304

305+
### Creating metrics
306+
307+
Similarly to Traces, you can create custom metrics in your application using the OpenTelemetry API and SDK.
308+
309+
In the following example application we demonstrate how to use metric instruments to record metrics with a Counter.
310+
```go lineNumbers=true
311+
var meter = otel.Meter("demo")
312+
timeAliveMetric, _ := meter.Int64Counter(
313+
"time_alive",
314+
instrument.WithDescription("Total amount of time that the application has been alive"),
315+
instrument.WithUnit("ms"),
316+
)
317+
go func() {
318+
for {
319+
timeAliveMetric.Add(context.Background(), 1000, attribute.String("a", "1")) // in millisconds
320+
time.Sleep(time.Second * time.Duration(1))
321+
}
322+
}()
323+
```
324+
259325
<SectionSeparator />
260326

261327
## Sample Application
262-
See [AWS Distro for OpenTelemetry Sample Code with Go SDK](https://github.com/aws-observability/aws-otel-go/tree/main/sampleapp) for instructions on setting up and using the sample app.
328+
See [AWS Distro for OpenTelemetry Sample Code with Go SDK](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/go-sample-app) for instructions on setting up and using the sample app.

src/docs/getting-started/java-sdk.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ backend.
1717

1818
## Getting Started
1919

20-
* [Auto-Instrumentation for Traces and Metrics with the Java agent](/docs/getting-started/java-sdk/trace-auto-instr)
21-
* [Manual Instrumentation for Traces and Metrics with the Java SDK](/docs/getting-started/java-sdk/trace-manual-instr)
20+
* [Auto-Instrumentation for Traces and Metrics with the Java agent](/docs/getting-started/java-sdk/auto-instr)
21+
* [Manual Instrumentation for Traces and Metrics with the Java SDK](/docs/getting-started/java-sdk/manual-instr)
2222

2323
## Sample Code
24-
* [Sample Spring App using OpenTelemetry Java Auto-Instrumentation](https://catalog.us-east-1.prod.workshops.aws/workshops/31676d37-bbe9-4992-9cd1-ceae13c5116c/en-US/aws-managed-oss/adot/javawalkthrough)
24+
* [Sample Spring App using OpenTelemetry Java Auto-Instrumentation Workshop](https://catalog.us-east-1.prod.workshops.aws/workshops/31676d37-bbe9-4992-9cd1-ceae13c5116c/en-US/aws-managed-oss/adot/javawalkthrough)
25+
* [Sample App using OpenTelemetry Java Auto-Instrumentation and Manual-Instrumentation](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/java-sample-app)

src/docs/getting-started/java-sdk/trace-auto-instr.mdx renamed to src/docs/getting-started/java-sdk/auto-instr.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description:
55
instrumentations for all supported libraries and all available data exporters, providing a complete out of the box
66
experience for tracing and metrics on AWS. The agent is preconfigured to generate trace IDs compatible with AWS X-Ray, which
77
will also work with any other tracing system, and enables trace propagation using W3C Trace Context, B3, and X-Ray.
8-
path: '/docs/getting-started/java-sdk/trace-auto-instr'
8+
path: '/docs/getting-started/java-sdk/auto-instr'
99
---
1010

1111
import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"

src/docs/getting-started/java-sdk/trace-manual-instr.mdx renamed to src/docs/getting-started/java-sdk/manual-instr.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: 'Manual Instrumentation for Traces and Metrics with the Java SDK'
33
description:
44
Learn how to get started with Java SDK for adding tracing to applications and libraries.
5-
path: '/docs/getting-started/java-sdk/trace-manual-instr'
5+
path: '/docs/getting-started/java-sdk/manual-instr'
66
---
77

88
import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"

src/docs/getting-started/javascript-sdk.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ In this tutorial, we will introduce how to use [OpenTelemetry JavaScript SDK](ht
2121

2222

2323
## Sample Code with JavaScript SDK
24-
* [AWS Distro for OpenTelemetry Sample Code with JavaScript SDK](https://github.com/aws-observability/aws-otel-js/tree/main/sample-apps)
24+
* [AWS Distro for OpenTelemetry Sample Code with JavaScript SDK](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/javascript-sample-app)
2525

src/docs/getting-started/python-sdk.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ The AWS Distro for OpenTelemetry (ADOT) Python refers to some components develop
1616

1717
## Getting Started
1818

19-
* [Auto Instrumentation for Traces with the Python SDK](/docs/getting-started/python-sdk/trace-auto-instr)
20-
* [Manual Instrumentation for Traces with the Python SDK](/docs/getting-started/python-sdk/trace-manual-instr)
19+
* [Auto Instrumentation for Traces and Metrics with the Python SDK](/docs/getting-started/python-sdk/auto-instr)
20+
* [Manual Instrumentation for Traces and Metrics with the Python SDK](/docs/getting-started/python-sdk/manual-instr)
2121

2222
## Sample Code
2323

24-
* [Sample Flask App using OpenTelemetry Python SDK Automatic Instrumentation](https://github.com/aws-observability/aws-otel-python/tree/main/integration-test-apps/auto-instrumentation/flask)
25-
* [Sample Flask App using OpenTelemetry Python SDK Manual Instrumentation](https://github.com/aws-observability/aws-otel-python/tree/main/integration-test-apps/manual-instrumentation/flask)
24+
* [Sample App using OpenTelemetry Python SDK Automatic Instrumentation](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/python-auto-instrumentation-sample-app)
25+
* [Sample App using OpenTelemetry Python SDK Manual Instrumentation](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/python-manual-instrumentation-sample-app)

src/docs/getting-started/python-sdk/trace-auto-instr.mdx renamed to src/docs/getting-started/python-sdk/auto-instr.mdx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: 'Tracing with the AWS Distro for OpenTelemetry Python Auto-Instrumentation and X-Ray'
2+
title: 'Tracing and Metrics with the AWS Distro for OpenTelemetry Python Auto-Instrumentation'
33
description:
44
OpenTelemetry provides different language SDKs to instrument code for collecting telemetry data in the application.
55
In this tutorial, we will introduce how to use OpenTelemetry Python SDK for traces and metrics instrumentation in the application...
6-
path: '/docs/getting-started/python-sdk/trace-auto-instr'
6+
path: '/docs/getting-started/python-sdk/auto-instr'
77
---
88

99
import SectionSeparator from "components/MdxSectionSeparator/sectionSeparator.jsx"
@@ -13,15 +13,15 @@ import SubSectionSeparator from "components/MdxSubSectionSeparator/subsectionSep
1313

1414
OpenTelemetry Python supports automatic instrumentation. It automatically produces spans with telemetry data describing the values used by the python frameworks in your application without adding a single line of code. This telemetry data can then be exported to a backend like AWS X-Ray using the ADOT Python `opentelemetry-sdk-extension-aws` package. We also strongly recommend using the `opentelemetry-propagator-aws-xray` package to support propagating the trace context across AWS services. This propagator handles the extraction and injecting of the [AWS X-Ray Tracing header](https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader) for requests from or to remote services.
1515

16-
In this guide, we walk through the steps needed to trace an application with auto-instrumentation.
16+
In this guide, we walk through the steps needed to trace an application and produce metrics with auto-instrumentation.
1717

1818
<SectionSeparator />
1919

2020
## Requirements
2121

2222
Python 3.6 or later is required to run an application using OpenTelemetry.
2323

24-
Note: You’ll also need to have the [ADOT Collector](https://aws-otel.github.io/docs/getting-started/collector) running to export traces to X-Ray.
24+
Note: You’ll also need to have the [ADOT Collector](https://aws-otel.github.io/docs/getting-started/collector) running to export traces and metrics.
2525

2626
<SectionSeparator />
2727

@@ -99,17 +99,34 @@ OTEL_PYTHON_ID_GENERATOR=xray \
9999
opentelemetry-instrument python3 ./path/to/your/app.py
100100
```
101101

102+
#### Creating Metrics
103+
104+
Similarly to Traces, you can create custom metrics in your application using the OpenTelemetry API and SDK.
105+
106+
In the following example application we demonstrate how to use metric instruments to record metrics with a Counter.
107+
```go lineNumbers=true
108+
meter = metrics.get_meter(__name__)
109+
time_alive_counter = meter.create_counter(
110+
name="time_alive",
111+
description="Total amount of time that the application has been alive",
112+
unit='ms'
113+
)
114+
while True:
115+
time_alive_counter.add(1, attributes={'a': '1'})
116+
time.Sleep(1)
117+
```
118+
102119
<SectionSeparator />
103120

104121
## Using Manual Instrumentation
105122

106-
Because there can only be one global `TracerProvider`, manual instrumentation should not instantiate its own `TracerProvider` if used together alongside auto-instrumentation. Given that the same `TracerProvider` is used, custom tracing works the same way when using automatic instrumentation or manual instrumentation. For information about custom trace instrumentation, see our [docs on manual instrumentation](/docs/getting-started/python-sdk/trace-manual-instr).
123+
Because there can only be one global `TracerProvider` and `MeterProvider`, manual instrumentation should not instantiate its own `TracerProvider` or `MeterProvider` if used together alongside auto-instrumentation. Given that the same `TracerProvider` and `MeterProvider` is used, custom tracing and metrics works the same way when using automatic instrumentation or manual instrumentation. For information about custom trace instrumentation, see our [docs on manual instrumentation](/docs/getting-started/python-sdk/manual-instr).
107124

108125
<SectionSeparator />
109126

110127
## Sample Application
111128

112-
See a [sample Flask App using OpenTelemetry Python SDK Automatic Instrumentation](https://github.com/aws-observability/aws-otel-python/tree/main/integration-test-apps/auto-instrumentation/flask).
129+
See a [Sample App using OpenTelemetry Python SDK Automatic Instrumentation](https://github.com/aws-observability/aws-otel-community/tree/master/sample-apps/python-auto-instrumentation-sample-app).
113130

114131
**NOTE:** Python Web Frameworks like Flask and Django normally include a "reloader" when running in `debug` mode so that you can apply changes during development. This reloader will break auto-instrumentation because the app is restarted without giving OpenTelemetry a chance to wrap the instrumented libraries. When using `debug` mode, set the `use_reloader=False` as is done in the referenced sample app:
115132

0 commit comments

Comments
 (0)