Skip to content

ASP.Net Core 9 hits System.InvalidOperationException: '"Can not set parent on already started Activity"' exception #906

@khteh

Description

@khteh

Describe the bug
ASP.Net Core 9 application hits the exception which prevents it from starting up.

To Reproduce
Steps to reproduce the behavior:

  1. Use this config '...'
  2. Then call '....'
  3. Then do '....'
  4. See error

Expected behavior
No exception and application starts up successfully.

Debug logs
Attach your debug logs.
See the documentation
about how to enable debug logging.

Click to expand
>	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.NotifyError(System.Exception exception) Line 1209	C#
 	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.SetParentId(System.Diagnostics.ActivityTraceId traceId, System.Diagnostics.ActivitySpanId spanId, System.Diagnostics.ActivityTraceFlags activityTraceFlags) Line 922	C#
 	Elastic.Apm.dll!Elastic.Apm.Model.Transaction.Transaction(Elastic.Apm.Logging.IApmLogger logger, string name, string type, Elastic.Apm.Sampler sampler, Elastic.Apm.Api.DistributedTracingData distributedTracingData, Elastic.Apm.Report.IPayloadSender sender, Elastic.Apm.Config.IConfiguration configuration, Elastic.Apm.ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer, Elastic.Apm.ServerInfo.IApmServerInfo apmServerInfo, Elastic.Apm.Metrics.MetricsProvider.BreakdownMetricsProvider breakdownMetricsProvider, bool ignoreActivity, long? timestamp, string id, string traceId, System.Collections.Generic.IEnumerable<Elastic.Apm.Api.SpanLink> links, System.Diagnostics.Activity current) Line 388	C#
 	Elastic.Apm.dll!Elastic.Apm.Api.Tracer.StartTransactionInternal(string name, string type, Elastic.Apm.Api.DistributedTracingData distributedTracingData, bool ignoreActivity, long? timestamp, string id, string traceId, System.Collections.Generic.IEnumerable<Elastic.Apm.Api.SpanLink> links, System.Diagnostics.Activity current) Line 66	C#
 	Elastic.Apm.dll!Elastic.Apm.Api.Tracer.StartTransactionInternal(string name, string type, long? timestamp, bool ignoreActivity, string id, string traceId, Elastic.Apm.Api.DistributedTracingData distributedTracingData, System.Collections.Generic.IEnumerable<Elastic.Apm.Api.SpanLink> links, System.Diagnostics.Activity current) Line 60	C#
 	Elastic.Apm.dll!Elastic.Apm.OpenTelemetry.ElasticActivityListener.CreateTransactionForActivity(System.Diagnostics.Activity activity, long timestamp, System.Collections.Generic.List<Elastic.Apm.Api.SpanLink> spanLinks) Line 152	C#
 	Elastic.Apm.dll!Elastic.Apm.OpenTelemetry.ElasticActivityListener.get_ActivityStarted.AnonymousMethod__19_0(System.Diagnostics.Activity activity)	C#
 	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.SynchronizedList<System.__Canon>.EnumWithAction(System.Action<System.__Canon, object> action, object arg) Line 75	C#
 	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.Start() Line 1002	C#
 	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.Create(System.Diagnostics.ActivitySource source, string name, System.Diagnostics.ActivityKind kind, string parentId, System.Diagnostics.ActivityContext parentContext, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> tags, System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink> links, System.DateTimeOffset startTime, System.Diagnostics.ActivityTagsCollection samplerTags, System.Diagnostics.ActivitySamplingResult request, bool startIt, System.Diagnostics.ActivityIdFormat idFormat, string traceState) Line 1174	C#
 	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.ActivitySource.CreateActivity(string name, System.Diagnostics.ActivityKind kind, System.Diagnostics.ActivityContext context, string parentId, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, object>> tags, System.Collections.Generic.IEnumerable<System.Diagnostics.ActivityLink> links, System.DateTimeOffset startTime, bool startIt, System.Diagnostics.ActivityIdFormat idFormat) Line 213	C#
 	System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.ActivitySource.StartActivity(string name, System.Diagnostics.ActivityKind kind) Line 91	C#
 	System.Net.Http.dll!System.Net.Http.ConnectionSetupDistributedTracing.StartWaitForConnectionActivity(System.Net.Http.HttpAuthority authority)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpConnectionWaiter<System.Net.Http.HttpConnection>.WaitForConnectionWithTelemetryAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpConnectionPool pool, bool async, System.Threading.CancellationToken requestCancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpConnectionWaiter<System.Net.Http.HttpConnection>.WaitForConnectionAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpConnectionPool pool, bool async, System.Threading.CancellationToken requestCancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(System.Net.Http.HttpRequestMessage request, bool async, bool doRequestAuth, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.AuthenticationHelper.SendWithAuthAsync(System.Net.Http.HttpRequestMessage request, System.Uri authUri, bool async, System.Net.ICredentials credentials, bool preAuthenticate, bool isProxyAuth, bool doRequestAuth, System.Net.Http.HttpConnectionPool pool, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpConnectionPool.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, bool doRequestAuth, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpConnectionPoolManager.SendAsyncCore(System.Net.Http.HttpRequestMessage request, System.Uri proxyUri, bool async, bool doRequestAuth, bool isProxyConnect, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpConnectionPoolManager.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, bool doRequestAuth, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpAuthenticatedConnectionHandler.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpMessageHandlerStage.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.Metrics.MetricsHandler.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpMessageHandlerStage.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.DiagnosticsHandler.SendAsyncCore(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.DiagnosticsHandler.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.RedirectHandler.SendAsync(System.Net.Http.HttpRequestMessage request, bool async, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.SocketsHttpHandler.SendAsync(System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpClient.SendAsync.__Core|83_0(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationTokenSource cts, bool disposeCts, System.Threading.CancellationTokenSource pendingRequestsCts, System.Threading.CancellationToken originalCancellationToken)	Unknown
 	System.Net.Http.dll!System.Net.Http.HttpClient.SendAsync(System.Net.Http.HttpRequestMessage request, System.Net.Http.HttpCompletionOption completionOption, System.Threading.CancellationToken cancellationToken)	Unknown
 	Elastic.Apm.dll!Elastic.Apm.BackendComm.CentralConfig.CentralConfigurationFetcher.FetchConfigHttpResponseImplAsync(System.Net.Http.HttpRequestMessage httpRequest) Line 178	C#
 	Elastic.Apm.dll!Elastic.Apm.BackendComm.CentralConfig.CentralConfigurationFetcher.FetchConfigHttpResponseAsync(System.Net.Http.HttpRequestMessage httpRequest) Line 185	C#
 	Elastic.Apm.dll!Elastic.Apm.BackendComm.CentralConfig.CentralConfigurationFetcher.WorkLoopIteration() Line 123	C#
 	Elastic.Apm.dll!Elastic.Apm.BackendComm.BackendCommComponentBase.WorkLoop() Line 76	C#
 	System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)	Unknown

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions