Replies: 2 comments 1 reply
-
We also need a similar solution now. The difference is that after reading opentelemrtry’s indicator collection, I found that if you want to add and export custom indicators to otlp, there are currently two methods:
services.AddOpenTelemetry().WithMetrics(builder =>
{
builder.AddMeter("your meter name1","your meter name2");
builder. AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation();
.AddHttpClientInstrumentation();
}).StartWithHost();
return services;
var myMtrics = new MyMtrics();
builder.AddInstrumentation(myMtrics); Finally, export to |
Beta Was this translation helpful? Give feedback.
-
I misunderstood your needs. I don't know if your needs are met, but they are met according to the original: //define a meter refrence https://learn.microsoft.com/en-us/dotnet/core/diagnostics/metrics-collection
Meter meter = new("MyCompany.MyProduct.MyLibrary", "1.0");
//create custom metrics
var metricRequest = meter.CreateHistogram<int>("my_custom_metric_request", "", "metrics description");
var metricResponse = meter.CreateHistogram<double>("my_custom_metric_response", "", "metrics description");
// config AspNetCoreInstrumentationOptions
services.AddOpenTelemetry().WithTracing(builder =>
{
builder.SetSampler(new AlwaysOnSampler());
builder.AddAspNetCoreInstrumentation(options =>
{
//http request
options.EnrichWithHttpRequest = (Activity activity, HttpRequest httpRequest) =>
{
int value = 1;
var tags = new List<KeyValuePair<string, object?>>();
//your any tags can add here,from httpRequest or fixed
tags.Add(KeyValuePair.Create("my_custom_time", (object?)DateTime.Now));
tags.Add(KeyValuePair.Create("my_custom_position", (object?)"Hangzhou"));
metricRequest.Record(value, tags.ToArray());
};
options.EnrichWithHttpResponse = (Activity activity, HttpResponse httpResponse) =>
{
double value = activity.Duration.TotalMilliseconds;
var tags = new List<KeyValuePair<string, object?>>();
tags.Add(KeyValuePair.Create("my_custom_time", (object?)DateTime.Now));
tags.Add(KeyValuePair.Create("my_custom_position", (object?)"Hangzhou"));
metricResponse.Record(value, tags.ToArray());
};
}).AddOtlpExporter();
});
services.AddOpenTelemetry().WithMetrics(builder => {
//add my custom metrics to otlp exporter
builder.AddMeter(meter.Name)
.AddAspNetCoreInstrumentation()
.AddOtlpExporter();
}); hope it can help you. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
A couple of years back we have built a much simplified home-grown kind of collector and now want to integrate that with OpenTelemetry. Our collector receives json data through REST calls and one type of data is performance information. We would like to send this to an OTel collector using OTLP as metric data (i.e. histogram) but we are not sure how to feed the data that we receive into the OTel pipeline.
Things we have considered so far:
I think we are not approaching this correctly. Does someone have a suggestion how to do this the right way?
Beta Was this translation helpful? Give feedback.
All reactions