Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics not sent from an ASP.NET application with RC9 #3078

Closed
devpro opened this issue Mar 23, 2022 · 2 comments
Closed

Metrics not sent from an ASP.NET application with RC9 #3078

devpro opened this issue Mar 23, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@devpro
Copy link

devpro commented Mar 23, 2022

Bug Report

  • Packages

    • OpenTelemetry.Exporter.OpenTelemetryProtocol 1.2.0-rc3
    • OpenTelemetry.Extensions.Hosting 1.0.0-rc9
    • OpenTelemetry.Instrumentation.AspNetCore 1.0.0-rc9
  • Runtime: net6.0 (.NET SDK: 6.0.201)

Symptom

There is a regression in the latest packages ("RC9"), the metrics are not sent anymore by an ASP.NET application using AddOpenTelemetryMetrics extension method.

What is the expected behavior?

Metrics should be sent to the exporter defined in AddOpenTelemetryMetrics extension method.

For example, OpenTelemetry collector console should display messages like:

otel-collector    | 2022-03-23T10:10:57.968Z    INFO    loggingexporter/logging_exporter.go:54  MetricsExporter {"#metrics": 2}

What is the actual behavior?

No metrics is sent.

Reproduce

  • Start an OpenTelemetry Collector listening on port 4317
#  docker-compose.yml
version: "3.9"
services:
  otel-collector:
    image: otel/opentelemetry-collector-contrib:latest
    container_name: otel-collector
    command: ["--config=/etc/otel-collector.yml"]
    volumes:
      - .opentelemetry-collector.yml:/etc/otel-collector.yml
    ports:
      - "4317:4317"

# opentelemetry-collector.yml
receivers:
  otlp:
    protocols:
      grpc:

exporters:
  logging:

service:
  pipelines:
    metrics:
      receivers: [otlp]
      exporters: [logging]
  • Create a new ASP.NET REST API .NET6 project and add OpenTelemetry packages
<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.2.0-rc3" />
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs" Version="1.0.0-rc9" />
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc9" />
    <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc9" />
  </ItemGroup>

</Project>
  • Update Progam.cs file
using System.Diagnostics;
using System.Diagnostics.Metrics;
using OpenTelemetry.Metrics;
using OpenTelemetry.Resources;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOpenTelemetryMetrics(builder =>
{
    builder.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"));
    builder.AddAspNetCoreInstrumentation();
    builder.AddMeter("MyApplicationMetrics");
    builder.AddOtlpExporter(options => options.Endpoint = new Uri("http://localhost:4317"));
});

var app = builder.Build();

var activitySource = new ActivitySource("MyApplicationActivitySource");
var meter = new Meter("MyApplicationMetrics");
var requestCounter = meter.CreateCounter<int>("compute_requests");

app.MapGet("/", () =>
{
    requestCounter.Add(1);
    return Results.Ok();
});

app.Run();
  • Run the web application and make a REST API call
# terminal #1
docker-compose up

# terminal #2
dotnet run --project <project_path>

# terminal #3
curl http://localhost:<port_numer>/

Additional Context

Same test is ok with previous versions:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.2.0-beta1" />
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol.Logs" Version="1.0.0-rc8" />
    <PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.0.0-rc8" />
    <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc8" />
  </ItemGroup>

</Project>
@devpro devpro added the bug Something isn't working label Mar 23, 2022
@cijothomas
Copy link
Member

cijothomas commented Mar 23, 2022

You are hit by this issue quite likely : #2991
use 1.0.0-rc10 (which is the newest version).

^ Ignore this.

@cijothomas
Copy link
Member

You are hit by this issue quite likely : #2991 use 1.0.0-rc10 (which is the newest version).

Oops.. More like the issue is with PeriodicExporter. This should be addressed in the coming release.
https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md#unreleased - The 1st item from unreleased should address your issue.

Until then use the workaround from #2979 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants