Unable to get AppInSight InstrumentationKey Docker Container run fails

Zafar Ahmed 1 Reputation point
2021-12-24T17:54:32.46+00:00

Here is the output from Docker-Compose Run Command in Pipeline. I don't know how to get the key from Application Insight resource in my subscription key is there but I don't know how to supply that key to pipeline at run time or substitute.

Creating network "lonewolfbov4_default" with the default driver
Creating lonewolfbov4_lonewolf.api.accountspayable_1 ...
Creating lonewolfbov4_lonewolf.api.accountspayable_1 ... done
Attaching to lonewolfbov4_lonewolf.api.accountspayable_1
lonewolf.api.accountspayable_1 | [14:43:26 INF] Starting up
lonewolf.api.accountspayable_1 | [14:43:26 FTL] Application start-up failed
lonewolf.api.accountspayable_1 | System.ArgumentNullException: Value cannot be null. (Parameter 'InstrumentationKey')
lonewolf.api.accountspayable_1 | at Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.set_InstrumentationKey(String value)
lonewolf.api.accountspayable_1 | at LoneWolf.API.AccountsPayable.Program.<>c.<CreateHostBuilder>b__1_0(HostBuilderContext hostingContext, LoggerConfiguration loggerConfiguration) in /src/LoneWolf.API.AccountsPayable/Program.cs:line 42
lonewolf.api.accountspayable_1 | at Serilog.SerilogHostBuilderExtensions.<>c__DisplayClass1_0.<UseSerilog>b__0(HostBuilderContext context, IServiceCollection collection)
lonewolf.api.accountspayable_1 | at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
lonewolf.api.accountspayable_1 | at Microsoft.Extensions.Hosting.HostBuilder.Build()
lonewolf.api.accountspayable_1 | at LoneWolf.API.AccountsPayable.Program.Main(String[] args) in /src/LoneWolf.API.AccountsPayable/Program.cs:line 28
lonewolfbov4_lonewolf.api.accountspayable_1 exited with code 0
Finishing: Run a Docker Compose command - Run

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,418 questions
Azure Managed Applications
Azure Managed Applications
An Azure service that enables managed service providers, independent software vendors, and enterprise IT teams to deliver turnkey solutions through the Azure Marketplace or service catalog.
113 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AnuragSingh-MSFT 20,431 Reputation points
    2021-12-27T08:35:46.377+00:00

    Hi @Zafar Ahmed ,

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Based on my understanding, you are trying to set the InstrumentationKey in the following method using the TelemetryConfiguration.InstrumentationKey property. Ref: TelemetryConfiguration.InstrumentationKey Property

    LoneWolf.API.AccountsPayable.Program.<>c.<CreateHostBuilder>b_1_0(HostBuilderContext hostingContext, LoggerConfiguration loggerConfiguration) in /src/LoneWolf.API.AccountsPayable/Program.cs:line 42  
    

    I would suggest using environment variable feature of dockerfile/docker compose to pass on the instrumentation key as environment variable in your PipeLine. More details are available here: Environment variable in Compose. This environment variable can then be read in your method and then assigned to the InstrumentationKey property.

    Please let me know if you have any questions.

    ---
    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.