Opentelemetry-dotnet: Can't use OtlpExporter in an Alpine docker image

Created on 9 Sep 2020  路  4Comments  路  Source: open-telemetry/opentelemetry-dotnet

Bug Report

List of NuGet packages and version that you are using:

  • OpenTelemetry.Exporter.OpenTelemetryProtocol 0.5.0-beta.2

Runtime version:

  • netcoreapp3.1

Symptom

When I run a .NET Core application in an Alpine-based docker image, and the app calls

Sdk.CreateTracerProviderBuilder()
    .AddSource("test.app")
    .AddOtlpExporter()
    .Build();

I get an exception because GRPC is missing a native dependency. It seems to be looking for a glibc library instead of the musl equivalent.

Unhandled exception. System.IO.IOException: Error loading native library "/App/runtimes/linux/native/libgrpc_csharp_ext.x64.so". Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /App/runtimes/linux/native/libgrpc_csharp_ext.x64.so)
   at Grpc.Core.Internal.UnmanagedLibrary..ctor(String[] libraryPathAlternatives)
   at Grpc.Core.Internal.NativeExtension.LoadUnmanagedLibrary()
   at Grpc.Core.Internal.NativeExtension.LoadNativeMethods()
   at Grpc.Core.Internal.NativeExtension.Get()
   at Grpc.Core.Internal.NativeMethods.Get()
   at Grpc.Core.GrpcEnvironment.GrpcNativeInit()
   at Grpc.Core.GrpcEnvironment..ctor()
   at Grpc.Core.GrpcEnvironment.AddRef()
   at Grpc.Core.Channel..ctor(String target, ChannelCredentials credentials, IEnumerable`1 options)
   at OpenTelemetry.Exporter.OpenTelemetryProtocol.OtlpExporter..ctor(OtlpExporterOptions options)
   at OpenTelemetry.Trace.OtlpExporterHelperExtensions.AddOtlpExporter(TracerProviderBuilder builder, Action`1 configure)
   at otlp_exporter_sample.Program.Main(String[] args) in C:\Users\damonb\projects\otlp-exporter-sample\Program.cs:line 11

What is the expected behavior?

The opentelemetry-dotnet libraries should work in an Alpine-based docker image (ideally in the dotnet/core Alpine image). I'd like to instrument the .NET code my team ships as docker images.

Reproduce

otlp-exporter-sample.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>otlp_exporter_sample</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="0.5.0-beta.2" />
  </ItemGroup>
</Project>

Program.cs:

using System;
using OpenTelemetry;
using OpenTelemetry.Trace;

namespace otlp_exporter_sample
{
    class Program
    {
        static void Main(string[] args)
        {
            using var tracerProvider = Sdk.CreateTracerProviderBuilder()
                .AddSource("test.app")
                .AddOtlpExporter()
                .Build();

            Console.WriteLine(tracerProvider.ToString());
        }
    }
}

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.8-alpine3.12
COPY bin/Release/netcoreapp3.1/publish/ App/
WORKDIR /App
ENTRYPOINT ["dotnet", "otlp-exporter-sample.dll"]

Save the above three files in a directory, cd to that directory, and run the following commands to reproduce the bug:

dotnet publish -c Release
docker build -t otlp-exporter-sample -f Dockerfile .
docker run -it --rm otlp-exporter-sample
exporter areaotlp bug p2

Most helpful comment

Hi @damonbarry , after some research, it looks like we have to add an step:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.8-alpine3.12 AS base
WORKDIR /app
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories
RUN apk update && apk add --no-cache bash libc6-compat=1.1.19-r11

After I added this, the docker ran normally.

It's a known issue: https://github.com/grpc/grpc/issues/21446

All 4 comments

@eddynaka Do you have free cycles to investigate this issue?

Hi @damonbarry , after some research, it looks like we have to add an step:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.8-alpine3.12 AS base
WORKDIR /app
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/v3.8/main' >> /etc/apk/repositories
RUN apk update && apk add --no-cache bash libc6-compat=1.1.19-r11

After I added this, the docker ran normally.

It's a known issue: https://github.com/grpc/grpc/issues/21446

Let us know if you face any other issue. We are closing this for now.

@eddynaka I rebuilt my container with the workaround, and it seems to have worked, thanks!

Was this page helpful?
0 / 5 - 0 ratings