Skip to content

Commit

Permalink
fix otel
Browse files Browse the repository at this point in the history
  • Loading branch information
YassinEldeeb committed Nov 17, 2024
1 parent 04f90ec commit e9e7035
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions plugins/telemetry/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use opentelemetry::trace::SpanKind;
use opentelemetry::trace::TraceError;
use opentelemetry::{InstrumentationLibrary, KeyValue};
use opentelemetry_otlp::WithExportConfig;
use opentelemetry_sdk::trace::Config;
use opentelemetry_sdk::trace::TracerProvider;
use opentelemetry_sdk::Resource;

#[derive(Debug)]
Expand Down Expand Up @@ -96,9 +98,11 @@ impl TelemetryPlugin {
fn build_otlp_identifiers(
service_name: String,
) -> (InstrumentationLibrary, Cow<'static, Resource>) {
let lib = InstrumentationLibrary::builder(LIB_NAME).build();
let resource = Cow::Owned(Resource::new([KeyValue::new("service.name", service_name)]));

let lib = InstrumentationLibrary::builder("my-lib").build();
let resource = Cow::Owned(Resource::new(vec![
KeyValue::new("service.name", service_name),
KeyValue::new("subgraph", "my-subgraph"),
]));
(lib, resource)
}

Expand All @@ -107,6 +111,17 @@ impl TelemetryPlugin {
service_name: &String,
target: &TelemetryTarget,
) -> Result<TracingReporter, TraceError> {
let resource = Resource::new(vec![
KeyValue::new("service.name", service_name.clone()),
KeyValue::new("subgraph", "my-subgraph"),
]);

let tracer_provider = TracerProvider::builder()
.with_config(Config::default().with_resource(resource))
.build();

opentelemetry::global::set_tracer_provider(tracer_provider);

use fastrace::collector::ConsoleReporter;
use fastrace::collector::Reporter;

Expand Down Expand Up @@ -197,6 +212,17 @@ impl TelemetryPlugin {
tenant_id: u32,
tracing_manager: &mut FastraceManager,
) -> Result<(), PluginError> {
let resource = Resource::new(vec![
KeyValue::new("service.name", self.config.service_name.clone()),
KeyValue::new("subgraph", "my-global-subgraph"),
]);

let config = Config::default().with_resource(resource);

let tracer_provider = TracerProvider::builder().with_config(config).build();

opentelemetry::global::set_tracer_provider(tracer_provider);

opentelemetry::global::set_error_handler(|error| {
tracing::error!("telemetry error: {:?}", error);
})
Expand Down

0 comments on commit e9e7035

Please sign in to comment.