-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tommycpp/span_limit
- Loading branch information
Showing
27 changed files
with
770 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "basic-otlp-http" | ||
version = "0.1.0" | ||
authors = ["rdan <dan.rusei@gmail.com>"] | ||
edition = "2018" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
opentelemetry = { path = "../../opentelemetry", features = ["rt-tokio", "metrics", "serialize"] } | ||
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["http-proto", "reqwest-client"] } | ||
tokio = { version = "1.0", features = ["full"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM rust:1.51 | ||
COPY . /usr/src/basic-otlp-http/ | ||
WORKDIR /usr/src/basic-otlp-http/ | ||
RUN cargo build --release | ||
RUN cargo install --path . | ||
CMD ["/usr/local/cargo/bin/basic-otlp-http"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
* The application send data directly to a Collector (port 55681) | ||
* Run the application locally, to run as a docker container you have to change the relative paths from the `Cargo.toml` | ||
* The Collector then sends the data to the appropriate backend, in this case JAEGER | ||
|
||
This demo uses `docker-compose` and by default runs against the `otel/opentelemetry-collector-dev:latest` image. | ||
|
||
```shell | ||
docker-compose up | ||
or | ||
docker-compose up -d | ||
``` | ||
|
||
In another terminal run the application `cargo run` | ||
|
||
Use the browser to see the trace: | ||
- Jaeger at http://0.0.0.0:16686 | ||
|
||
Tear it down: | ||
|
||
```shell | ||
docker-compose down | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
version: "2" | ||
services: | ||
|
||
# Jaeger | ||
jaeger-all-in-one: | ||
image: jaegertracing/all-in-one:latest | ||
ports: | ||
- "16686:16686" | ||
- "14268" | ||
- "14250" | ||
|
||
# Collector | ||
otel-collector: | ||
image: otel/opentelemetry-collector-dev:latest | ||
command: ["--config=/etc/otel-collector-config.yaml", "${OTELCOL_ARGS}"] | ||
volumes: | ||
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml | ||
ports: | ||
- "1888:1888" # pprof extension | ||
- "13133:13133" # health_check extension | ||
- "4317" # OTLP gRPC receiver | ||
- "55681:55681" # OTLP HTTP receiver | ||
- "55670:55679" # zpages extension | ||
depends_on: | ||
- jaeger-all-in-one | ||
|
||
|
||
# metrics-rust: | ||
# build: | ||
# dockerfile: $PWD/Dockerfile | ||
# context: ./basic-otlp-http | ||
# environment: | ||
# - OTLP_TONIC_ENDPOINT=otel-collector:4317 | ||
# depends_on: | ||
# - otel-collector | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
http: | ||
grpc: | ||
|
||
exporters: | ||
logging: | ||
loglevel: debug | ||
|
||
jaeger: | ||
endpoint: jaeger-all-in-one:14250 | ||
insecure: true | ||
|
||
processors: | ||
batch: | ||
|
||
extensions: | ||
health_check: | ||
pprof: | ||
endpoint: :1888 | ||
zpages: | ||
endpoint: :55679 | ||
|
||
service: | ||
extensions: [pprof, zpages, health_check] | ||
pipelines: | ||
traces: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [logging, jaeger] | ||
metrics: | ||
receivers: [otlp] | ||
processors: [batch] | ||
exporters: [logging] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use opentelemetry::trace::TraceError; | ||
use opentelemetry::{global, sdk::trace as sdktrace}; | ||
use opentelemetry::{ | ||
trace::{TraceContextExt, Tracer}, | ||
Key, | ||
}; | ||
use std::error::Error; | ||
use std::time::Duration; | ||
|
||
fn init_tracer() -> Result<sdktrace::Tracer, TraceError> { | ||
opentelemetry_otlp::new_pipeline() | ||
.with_endpoint("http://localhost:55681/v1/traces") | ||
.with_http() | ||
.install_batch(opentelemetry::runtime::Tokio) | ||
} | ||
|
||
const LEMONS_KEY: Key = Key::from_static_str("ex.com/lemons"); | ||
const ANOTHER_KEY: Key = Key::from_static_str("ex.com/another"); | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> { | ||
let _ = init_tracer()?; | ||
|
||
let tracer = global::tracer("ex.com/basic"); | ||
|
||
tracer.in_span("operation", |cx| { | ||
let span = cx.span(); | ||
span.add_event( | ||
"Nice operation!".to_string(), | ||
vec![Key::new("bogons").i64(100)], | ||
); | ||
span.set_attribute(ANOTHER_KEY.string("yes")); | ||
|
||
tracer.in_span("Sub operation...", |cx| { | ||
let span = cx.span(); | ||
span.set_attribute(LEMONS_KEY.string("five")); | ||
|
||
span.add_event("Sub span event".to_string(), vec![]); | ||
}); | ||
}); | ||
|
||
// wait for 1 minutes so that we could see metrics being pushed via OTLP every 10 seconds. | ||
tokio::time::sleep(Duration::from_secs(60)).await; | ||
|
||
global::shutdown_tracer_provider(); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
# Basic OpenTelemetry Example | ||
# Basic OTLP exporter Example | ||
|
||
This example shows basic span and metric usage, and exports to the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP with a custom metric aggregator selector. | ||
This example shows how to configure OTLP metrics exporter to use custom aggregator selectors and custom export kind selectors. | ||
|
||
## Prerequisite | ||
You should first start a `opentelemetry-collector` on localhost using the default configuration. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Basic OpenTelemetry Example | ||
# Basic OTLP exporter Example | ||
|
||
This example shows basic span and metric usage, and exports to the [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector) via OTLP. | ||
|
||
## Prerequisite | ||
You should first start a `opentelemetry-collector` on localhost using the default configuration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.