Skip to content

Commit 04a33af

Browse files
authored
Merge branch 'main' into func-test-http
2 parents 82d9d51 + ca6c67e commit 04a33af

File tree

136 files changed

+2282
-1783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+2282
-1783
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,6 @@ jobs:
8080
cargo install [email protected]
8181
cd ${{ matrix.example }}
8282
cargo check-external-types --config allowed-external-types.toml
83-
non-default-examples:
84-
strategy:
85-
matrix:
86-
os: [ windows-latest, ubuntu-latest ]
87-
example: [opentelemetry-otlp/examples/basic-otlp]
88-
runs-on: ${{ matrix.os }}
89-
steps:
90-
- uses: actions/checkout@v4
91-
with:
92-
submodules: true
93-
- uses: dtolnay/rust-toolchain@stable
94-
with:
95-
components: rustfmt
96-
- uses: arduino/setup-protoc@v3
97-
with:
98-
repo-token: ${{ secrets.GITHUB_TOKEN }}
99-
- name: Build
100-
run: |
101-
cd ${{ matrix.example }}
102-
cargo build --verbose
10383
msrv:
10484
strategy:
10585
matrix:
@@ -132,7 +112,7 @@ jobs:
132112
runs-on: ubuntu-latest
133113
steps:
134114
- uses: actions/checkout@v4
135-
- uses: dtolnay/rust-toolchain@nightly
115+
- uses: dtolnay/rust-toolchain@stable
136116
with:
137117
components: rustfmt
138118
- uses: arduino/setup-protoc@v3

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ It's important to regularly review and remove the `otel_unstable` flag from the
169169
The potential features include:
170170

171171
- Stable and non-experimental features that compliant to specification, and have a feature flag to minimize compilation size. Example: feature flags for signals (like `logs`, `traces`, `metrics`) and runtimes (`rt-tokio`, `rt-tokio-current-thread`, `rt-async-std`).
172-
- Stable and non-experimental features, although not part of the specification, are crucial for enhancing the tracing/log crate's functionality or boosting performance. These features are also subject to discussion and approval by the OpenTelemetry Rust Maintainers. An example of such a feature is `logs_level_enabled`.
172+
- Stable and non-experimental features, although not part of the specification, are crucial for enhancing the tracing/log crate's functionality or boosting performance. These features are also subject to discussion and approval by the OpenTelemetry Rust Maintainers.
173173

174174
All such features should adhere to naming convention `<signal>_<feature_name>`
175175

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ tokio-stream = "0.1"
4747
tracing = { version = "0.1", default-features = false }
4848
tracing-core = { version = "0.1", default-features = false }
4949
tracing-subscriber = { version = "0.3", default-features = false }
50-
url = { version = "2.5", default-features = false }
50+
url = { version = "2.5.2", default-features = false } #https://github.com/servo/rust-url/issues/992

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ observability tools.
2727

2828
| Signal/Component | Overall Status |
2929
| -------------------- | ------------------ |
30-
| Logs-API | Beta* |
30+
| Logs-API | RC* |
3131
| Logs-SDK | Beta |
3232
| Logs-OTLP Exporter | Beta |
3333
| Logs-Appender-Tracing | Beta |
34-
| Metrics-API | Beta |
35-
| Metrics-SDK | Alpha |
36-
| Metrics-OTLP Exporter | Alpha |
34+
| Metrics-API | RC |
35+
| Metrics-SDK | Beta |
36+
| Metrics-OTLP Exporter | Beta |
3737
| Traces-API | Beta |
3838
| Traces-SDK | Beta |
3939
| Traces-OTLP Exporter | Beta |

examples/metrics-advanced/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ publish = false
77

88
[dependencies]
99
opentelemetry = { path = "../../opentelemetry", features = ["metrics"] }
10-
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["metrics", "rt-tokio"] }
10+
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["spec_unstable_metrics_views", "rt-tokio"] }
1111
opentelemetry-stdout = { path = "../../opentelemetry-stdout", features = ["metrics"] }
1212
tokio = { workspace = true, features = ["full"] }
1313
serde_json = { workspace = true }

examples/metrics-advanced/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use opentelemetry::global;
22
use opentelemetry::Key;
33
use opentelemetry::KeyValue;
44
use opentelemetry_sdk::metrics::{
5-
data::Temporality, Aggregation, Instrument, PeriodicReader, SdkMeterProvider, Stream,
5+
Aggregation, Instrument, PeriodicReader, SdkMeterProvider, Stream, Temporality,
66
};
77
use opentelemetry_sdk::{runtime, Resource};
88
use std::error::Error;

examples/metrics-basic/src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use opentelemetry::global;
2-
use opentelemetry::KeyValue;
1+
use opentelemetry::{global, KeyValue};
32
use opentelemetry_sdk::metrics::{PeriodicReader, SdkMeterProvider};
43
use opentelemetry_sdk::{runtime, Resource};
54
use std::error::Error;
@@ -8,7 +7,7 @@ use std::vec;
87
fn init_meter_provider() -> opentelemetry_sdk::metrics::SdkMeterProvider {
98
let exporter = opentelemetry_stdout::MetricExporterBuilder::default()
109
// Build exporter using Delta Temporality (Defaults to Temporality::Cumulative)
11-
// .with_temporality(data::Temporality::Delta)
10+
// .with_temporality(opentelemetry_sdk::metrics::Temporality::Delta)
1211
.build();
1312
let reader = PeriodicReader::builder(exporter, runtime::Tokio).build();
1413
let provider = SdkMeterProvider::builder()

examples/self-diagnostics/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ publish = false
99
opentelemetry = { path = "../../opentelemetry" }
1010
opentelemetry_sdk = { path = "../../opentelemetry-sdk", features = ["rt-tokio"]}
1111
opentelemetry-stdout = { path = "../../opentelemetry-stdout"}
12-
opentelemetry-appender-tracing = { path = "../../opentelemetry-appender-tracing"}
1312
tokio = { workspace = true, features = ["full"] }
1413
tracing = { workspace = true, features = ["std"]}
1514
tracing-core = { workspace = true }
1615
tracing-subscriber = { version = "0.3.18", features = ["env-filter","registry", "std"]}
17-
opentelemetry-otlp = { path = "../../opentelemetry-otlp", features = ["http-proto", "reqwest-client", "logs"] }
18-
once_cell ={ version = "1.19.0"}
19-
ctrlc = "3.4"

examples/self-diagnostics/Dockerfile

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 23 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,28 @@
11
# Basic OpenTelemetry metrics example with custom error handler:
22

3-
This example shows how to setup the custom error handler for self-diagnostics.
4-
5-
## Custom Error Handling:
6-
7-
A custom error handler is set up to capture and record errors using the `tracing` crate's `error!` macro. These errors are then exported to a collector using the `opentelemetry-appender-tracing` crate, which utilizes the OTLP log exporter over `HTTP/protobuf`. As a result, any errors generated by the configured OTLP metrics pipeline are funneled through this custom error handler for proper recording and export.
3+
This example shows how to self-diagnose OpenTelemetry by enabling its internal
4+
logs. OpenTelemetry crates publish internal logs when "internal-logs" feature is
5+
enabled. This feature is enabled by default. Internal logs are published using
6+
`tracing` events, and hence, a `tracing` subscriber must be configured without
7+
which the logs are simply discarded.
88

99
## Filtering logs from external dependencies of OTLP Exporter:
1010

11-
The example configures a tracing `filter` to restrict logs from external crates (`hyper`, `tonic`, and `reqwest`) used by the OTLP Exporter to the `error` level. This helps prevent an infinite loop of log generation when these crates emit logs that are picked up by the tracing subscriber.
12-
13-
## Ensure that the internally generated errors are logged only once:
14-
15-
By using a hashset to track seen errors, the custom error handler ensures that the same error is not logged multiple times. This is particularly useful for handling scenarios where continuous error logging might occur, such as when the OpenTelemetry collector is not running.
16-
17-
18-
## Usage
19-
20-
### `docker-compose`
21-
22-
By default runs against the `otel/opentelemetry-collector:latest` image, and uses `reqwest-client`
23-
as the http client, using http as the transport.
24-
25-
```shell
26-
docker-compose up
27-
```
28-
29-
In another terminal run the application `cargo run`
30-
31-
The docker-compose terminal will display logs, traces, metrics.
32-
33-
Press Ctrl+C to stop the collector, and then tear it down:
34-
35-
```shell
36-
docker-compose down
37-
```
38-
39-
### Manual
40-
41-
If you don't want to use `docker-compose`, you can manually run the `otel/opentelemetry-collector` container
42-
and inspect the logs to see traces being transferred.
43-
44-
On Unix based systems use:
45-
46-
```shell
47-
# From the current directory, run `opentelemetry-collector`
48-
docker run --rm -it -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml
49-
```
50-
51-
On Windows use:
52-
53-
```shell
54-
# From the current directory, run `opentelemetry-collector`
55-
docker run --rm -it -p 4318:4318 -v "%cd%":/cfg otel/opentelemetry-collector:latest --config=/cfg/otel-collector-config.yaml
56-
```
57-
58-
Run the app which exports logs, metrics and traces via OTLP to the collector
59-
60-
```shell
61-
cargo run
62-
```
63-
64-
### Output:
65-
66-
- If the docker instance for collector is running, below error should be logged into the container. There won't be any logs from the `hyper`, `reqwest` and `tonic` crates.
67-
```
68-
otel-collector-1 | 2024-06-05T17:09:46.926Z info LogExporter {"kind": "exporter", "data_type": "logs", "name": "logging", "resource logs": 1, "log records": 1}
69-
otel-collector-1 | 2024-06-05T17:09:46.926Z info ResourceLog #0
70-
otel-collector-1 | Resource SchemaURL:
71-
otel-collector-1 | Resource attributes:
72-
otel-collector-1 | -> telemetry.sdk.name: Str(opentelemetry)
73-
otel-collector-1 | -> telemetry.sdk.version: Str(0.23.0)
74-
otel-collector-1 | -> telemetry.sdk.language: Str(rust)
75-
otel-collector-1 | -> service.name: Str(unknown_service)
76-
otel-collector-1 | ScopeLogs #0
77-
otel-collector-1 | ScopeLogs SchemaURL:
78-
otel-collector-1 | InstrumentationScope opentelemetry-appender-tracing 0.4.0
79-
otel-collector-1 | LogRecord #0
80-
otel-collector-1 | ObservedTimestamp: 2024-06-05 17:09:45.931951161 +0000 UTC
81-
otel-collector-1 | Timestamp: 1970-01-01 00:00:00 +0000 UTC
82-
otel-collector-1 | SeverityText: ERROR
83-
otel-collector-1 | SeverityNumber: Error(17)
84-
otel-collector-1 | Body: Str(OpenTelemetry metrics error occurred: Metrics error: Warning: Maximum data points for metric stream exceeded. Entry added to overflow. Subsequent overflows to same metric until next collect will not be logged.)
85-
otel-collector-1 | Attributes:
86-
otel-collector-1 | -> name: Str(event examples/self-diagnostics/src/main.rs:42)
87-
otel-collector-1 | Trace ID:
88-
otel-collector-1 | Span ID:
89-
otel-collector-1 | Flags: 0
90-
otel-collector-1 | {"kind": "exporter", "data_type": "logs", "name": "logging"}
91-
```
92-
93-
- The SDK will keep trying to upload metrics at regular intervals if the collector's Docker instance is down. To avoid a logging loop, internal errors like 'Connection refused' will be attempted to be logged only once.
11+
The example configures a tracing `filter` to restrict logs from external crates
12+
(`hyper`, `tonic`, and `reqwest` etc.) used by the OTLP Exporter to the `error`
13+
level. This helps prevent an infinite loop of log generation when these crates
14+
emit logs that are picked up by the tracing subscriber. This is only a
15+
workaround until [the root
16+
issue](https://github.com/open-telemetry/opentelemetry-rust/issues/761) is
17+
resolved.
18+
19+
## Filtering logs to be send to OpenTelemetry itself
20+
21+
If you use [OpenTelemetry Tracing
22+
Appender](../../opentelemetry-appender-tracing/README.md) to send `tracing` logs
23+
to OpenTelemetry, then enabling OpenTelemetry internal logs can also cause
24+
infinite, recursive logging. You can filter out all OpenTelemetry internal logs
25+
from being sent to [OpenTelemetry Tracing
26+
Appender](../../opentelemetry-appender-tracing/README.md) using a filter, like
27+
"add_directive("opentelemetry=off".parse().unwrap())" being done for tracing's
28+
`FmtSubscriber`.

0 commit comments

Comments
 (0)