Skip to content

[BUG] Unable to cast object of type 'Elastic.Apm.Model.NoopSpan' to type 'Elastic.Apm.Model.Span' #2176

Open
@molszews

Description

@molszews

APM Agent version

1.23.0

Environment

net6.0

Describe the bug

Error messages are logged when apm is disabled.

To Reproduce

Start app with UseAllElasticApm() and "Enabled" setting set to false in appsettings.json

  "ElasticApm": {
    "Enabled": false
}

after while error messages starts to log

[14:10:53 ERR] {AuditDiagnosticsListener} An exception occured calling OnNext on an ElasticsearchDiagnostic observer
System.InvalidCastException: Unable to cast object of type 'Elastic.Apm.Model.NoopSpan' to type 'Elastic.Apm.Model.Span'.
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.TryStartElasticsearchSpan(String name, Span& span, Uri instanceUri)
   at Elastic.Apm.Elasticsearch.AuditDiagnosticsListener.OnAudit(String event, Audit audit)
   at Elastic.Apm.Elasticsearch.AuditDiagnosticsListener.<.ctor>b__0_0(KeyValuePair`2 a)
   at Elasticsearch.Net.Diagnostics.TypedDiagnosticObserverBase`1.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.HandleOnNext(KeyValuePair`2 kv)
[14:10:53 ERR] {AuditDiagnosticsListener} An exception occured calling OnNext on an ElasticsearchDiagnostic observer
System.InvalidCastException: Unable to cast object of type 'Elastic.Apm.Model.NoopSpan' to type 'Elastic.Apm.Model.Span'.
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.TryStartElasticsearchSpan(String name, Span& span, Uri instanceUri)
   at Elastic.Apm.Elasticsearch.AuditDiagnosticsListener.OnAudit(String event, Audit audit)
   at Elastic.Apm.Elasticsearch.AuditDiagnosticsListener.<.ctor>b__0_0(KeyValuePair`2 a)
   at Elasticsearch.Net.Diagnostics.TypedDiagnosticObserverBase`1.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.HandleOnNext(KeyValuePair`2 kv)
[14:10:53 ERR] {HttpConnectionDiagnosticsListener} An exception occured calling OnNext on an ElasticsearchDiagnostic observer
System.InvalidCastException: Unable to cast object of type 'Elastic.Apm.Model.NoopSpan' to type 'Elastic.Apm.Model.Span'.
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.TryStartElasticsearchSpan(String name, Span& span, Uri instanceUri)
   at Elastic.Apm.Elasticsearch.HttpConnectionDiagnosticsListener.OnRequestData(String event, RequestData requestData)
   at Elastic.Apm.Elasticsearch.HttpConnectionDiagnosticsListener.<.ctor>b__0_0(KeyValuePair`2 a)
   at Elasticsearch.Net.Diagnostics.TypedDiagnosticObserverBase`2.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.HandleOnNext(KeyValuePair`2 kv)
[14:10:53 ERR] {HttpConnectionDiagnosticsListener} Failed to find current span in ConcurrentDictionary 00-372ff7fc0a235ce546f5c9a0e39ec8e9-91b96ddd006263d9-00
[14:10:53 ERR] {HttpConnectionDiagnosticsListener} An exception occured calling OnNext on an ElasticsearchDiagnostic observer
System.InvalidCastException: Unable to cast object of type 'Elastic.Apm.Model.NoopSpan' to type 'Elastic.Apm.Model.Span'.
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.TryStartElasticsearchSpan(String name, Span& span, Uri instanceUri)
   at Elastic.Apm.Elasticsearch.HttpConnectionDiagnosticsListener.OnRequestData(String event, RequestData requestData)
   at Elastic.Apm.Elasticsearch.HttpConnectionDiagnosticsListener.<.ctor>b__0_0(KeyValuePair`2 a)
   at Elasticsearch.Net.Diagnostics.TypedDiagnosticObserverBase`2.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
   at Elastic.Apm.Elasticsearch.ElasticsearchDiagnosticsListenerBase.HandleOnNext(KeyValuePair`2 kv)

Expected behavior

No errors re casting NoopSpan to Span are logged.
No errors re Failed to find current span in ConcurrentDictionary 00-372ff7fc0a235ce546f5c9a0e39ec8e9-91b96ddd006263d9-00 are logged.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions