-
Hello!
I cought
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
If they have told you to use their
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource("Npgsql")
.AddProcessor(new NpgSqlMetricsProcessor())
.Build(); public class NpgSqlMetricsProcessor : BaseProcessor<Activity>
{
internal Meter CustomMeter = new Meter("CustomMeter");
internal Histogram<double> CustomMetric;
public NpgSqlMetricsProcessor()
{
this.CustomMetric = this.CustomMeter.CreateHistogram<double>("CustomMetric");
}
public override void OnStart(Activity activity)
{
}
public override void OnEnd(Activity activity)
{
if (activity.Source.Name == "Npgsql" && activity.DisplayName == "ExpectedActivityName")
{
this.CustomMetric.Record(activity.Duration.TotalMilliseconds, new KeyValuePair<string, object?>("Status", activity.Status));
}
}
} |
Beta Was this translation helpful? Give feedback.
If they have told you to use their
ActivitySource
, there are two obvious approaches to achieving what you want:You could either create an ActivityListener and configure it accordingly to listen to the activities created by their
ActivitySource
. With this approach, you would have to be careful with the order of registration ofActivityListener
s (as OpenTelemetry Tracing SDK also creates its ownActivityListener
) and ensure that you don't mess up with the sampling of activitites.You could use a custom processor that would emit the required m…