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

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

Closed
owennw opened this issue Mar 15, 2021 · 1 comment · Fixed by #1932
Labels
bug Something isn't working help wanted Good for taking. Extra help will be provided by maintainers pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Milestone

Comments

@owennw
Copy link

owennw commented Mar 15, 2021

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}");
@cijothomas cijothomas added pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package bug Something isn't working labels Mar 15, 2021
@cijothomas
Copy link
Member

Apart from fixing this particular bug, we need to protect all these static field initializations with try..catch, as these exceptions typically crash application.

@cijothomas cijothomas added the help wanted Good for taking. Extra help will be provided by maintainers label Mar 23, 2021
mbergin added a commit to mbergin/opentelemetry-dotnet that referenced this issue Mar 23, 2021
@cijothomas cijothomas added this to the 1.1.0-beta2 milestone Mar 24, 2021
mbergin added a commit to mbergin/opentelemetry-dotnet that referenced this issue Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Good for taking. Extra help will be provided by maintainers pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants