Skip to content

Commit 9effb5d

Browse files
fix: Update instrumentation to support Elasticsearch v8.11.0 (#2100)
Co-authored-by: Alex Hemsath <[email protected]>
1 parent 576adbe commit 9effb5d

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/Elasticsearch/Instrumentation.xml

+13
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,18 @@ SPDX-License-Identifier: Apache-2.0
3232
</match>
3333
</tracerFactory>
3434

35+
<!--8.10.0+-->
36+
<tracerFactory name="RequestWrapper">
37+
<match assemblyName="Elastic.Transport" className="Elastic.Transport.DefaultHttpTransport`1">
38+
<exactMethodMatcher methodName="Request" parameters="Elastic.Transport.HttpMethod,System.String,Elastic.Transport.PostData,Elastic.Transport.RequestParameters,Elastic.Transport.Diagnostics.OpenTelemetryData&amp;" />
39+
</match>
40+
</tracerFactory>
41+
42+
<tracerFactory name="RequestWrapper">
43+
<match assemblyName="Elastic.Transport" className="Elastic.Transport.DefaultHttpTransport`1">
44+
<exactMethodMatcher methodName="RequestAsync" parameters="Elastic.Transport.HttpMethod,System.String,Elastic.Transport.PostData,Elastic.Transport.RequestParameters,Elastic.Transport.Diagnostics.OpenTelemetryData&amp;,System.Threading.CancellationToken" />
45+
</match>
46+
</tracerFactory>
47+
3548
</instrumentation>
3649
</extension>

src/Agent/NewRelic/Agent/Extensions/Providers/Wrapper/Elasticsearch/RequestWrapper.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 New Relic, Inc. All rights reserved.
1+
// Copyright 2020 New Relic, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
using System;
@@ -39,9 +39,13 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
3939
{
4040
var indexOfRequestParams = 3; // unless it's Elasticsearch.Net/NEST and async
4141

42-
if (instrumentedMethodCall.IsAsync)
42+
var isAsync = instrumentedMethodCall.IsAsync ||
43+
instrumentedMethodCall.InstrumentedMethodInfo.Method.MethodName == "RequestAsync";
44+
45+
if (isAsync)
4346
{
4447
transaction.AttachToAsync();
48+
transaction.DetachFromPrimary(); //Remove from thread-local type storage
4549

4650
var parameterTypeNamesList = instrumentedMethodCall.InstrumentedMethodInfo.Method.ParameterTypeNames.Split(',');
4751
if (parameterTypeNamesList[4] == "Elasticsearch.Net.IRequestParameters")
@@ -70,7 +74,7 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
7074
var segment = transactionExperimental.StartSegment(instrumentedMethodCall.MethodCall);
7175
segment.GetExperimentalApi().SetSegmentData(datastoreSegmentData).MakeLeaf();
7276

73-
if (instrumentedMethodCall.IsAsync)
77+
if (isAsync)
7478
{
7579
return Delegates.GetAsyncDelegateFor<Task>(agent, segment, true, InvokeTryProcessResponse, TaskContinuationOptions.ExecuteSynchronously);
7680

tests/Agent/IntegrationTests/SharedApplications/Common/MultiFunctionApplicationHelpers/MultiFunctionApplicationHelpers.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@
124124
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.0" Condition="'$(TargetFramework)' == 'net462'" />
125125
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.9" Condition="'$(TargetFramework)' == 'net471'" />
126126
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.9" Condition="'$(TargetFramework)' == 'net48'" />
127-
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.9.3" Condition="'$(TargetFramework)' == 'net481'" />
127+
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.11.0" Condition="'$(TargetFramework)' == 'net481'" />
128128

129129
<!-- Elastic.Clients.Elasticsearch .NET/Core references - only actually testing oldest and newest -->
130130
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.0" Condition="'$(TargetFramework)' == 'net6.0'" />
131-
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.9.3" Condition="'$(TargetFramework)' == 'net7.0'" />
131+
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.11.0" Condition="'$(TargetFramework)' == 'net7.0'" />
132132

133133
<!-- Serilog .NET framework references -->
134134
<PackageReference Include="Serilog" Version="1.5.14" Condition="'$(TargetFramework)' == 'net462'" />

tests/Agent/IntegrationTests/UnboundedIntegrationTests/Elasticsearch/ElasticsearchTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 New Relic, Inc. All rights reserved.
1+
// Copyright 2020 New Relic, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44

@@ -174,9 +174,9 @@ private void ValidateOperation(string operationName)
174174

175175
var operationDatastoreSpans = spanEvents.Where(@event => @event.IntrinsicAttributes["traceId"].ToString().Equals(traceId) && @event.IntrinsicAttributes["name"].ToString().Contains("Datastore/statement/Elasticsearch"));
176176

177-
var operationDatastoreAgentAttributes = operationDatastoreSpans.FirstOrDefault().AgentAttributes;
177+
var operationDatastoreAgentAttributes = operationDatastoreSpans.FirstOrDefault()?.AgentAttributes;
178178

179-
var uri = operationDatastoreAgentAttributes.Where(x => x.Key == "peer.address").FirstOrDefault().Value;
179+
var uri = operationDatastoreAgentAttributes?.Where(x => x.Key == "peer.address").FirstOrDefault().Value;
180180

181181
NrAssert.Multiple
182182
(

0 commit comments

Comments
 (0)