Skip to content

Services running on AWS Lambda fail to start due to exception thrown in constructing OpenTelemetry classes #1908

@owennw

Description

@owennw

This line

private static readonly string FileVersion = FileVersionInfo.GetVersionInfo(typeof(Resource).Assembly.Location).FileVersion;

at https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/src/OpenTelemetry/Resources/ResourceBuilderExtensions.cs#L28

fails on application startup inside an AWS Lambda as the assemblies required are not loaded from disk.

Example stack trace:


System.TypeInitializationException: The type initializer for 'OpenTelemetry.Resources.ResourceBuilderExtensions' threw an exception.
---> System.ArgumentException: The path is empty. (Parameter 'path')
at System.IO.Path.GetFullPath(String path)
at System.Diagnostics.FileVersionInfo.GetVersionInfo(String fileName)
at OpenTelemetry.Resources.ResourceBuilderExtensions..cctor()

Reproduction / suggestion:

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;

// Adjust as necessary
var ot = @"opentelemetry\1.0.1\lib\netstandard2.0\OpenTelemetry.dll";

var assemblyLoadFile = Assembly.LoadFile(ot);
var assemblyLoad = Assembly.Load(File.ReadAllBytes(ot));

Console.WriteLine($"Assembly.LoadFile, proposed method: {assemblyLoadFile.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version}");
Console.WriteLine($"Assembly.LoadFile, current method: {FileVersionInfo.GetVersionInfo(assemblyLoadFile.Location).FileVersion}");
Console.WriteLine($"Assembly.Load, proposed method: {assemblyLoad.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version}");
Console.WriteLine($"Assembly.Load, current method (fails): {FileVersionInfo.GetVersionInfo(assemblyLoad.Location).FileVersion}");

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedGood for taking. Extra help will be provided by maintainerspkg:OpenTelemetryIssues related to OpenTelemetry NuGet package

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions