Skip to content

Commit

Permalink
fix: Update instrumentation to support Elasticsearch v8.11.0 (#2100)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Hemsath <ahemsath@newrelic.com>
  • Loading branch information
tippmar-nr and nr-ahemsath authored Nov 28, 2023
1 parent 576adbe commit 9effb5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,18 @@ SPDX-License-Identifier: Apache-2.0
</match>
</tracerFactory>

<!--8.10.0+-->
<tracerFactory name="RequestWrapper">
<match assemblyName="Elastic.Transport" className="Elastic.Transport.DefaultHttpTransport`1">
<exactMethodMatcher methodName="Request" parameters="Elastic.Transport.HttpMethod,System.String,Elastic.Transport.PostData,Elastic.Transport.RequestParameters,Elastic.Transport.Diagnostics.OpenTelemetryData&amp;" />
</match>
</tracerFactory>

<tracerFactory name="RequestWrapper">
<match assemblyName="Elastic.Transport" className="Elastic.Transport.DefaultHttpTransport`1">
<exactMethodMatcher methodName="RequestAsync" parameters="Elastic.Transport.HttpMethod,System.String,Elastic.Transport.PostData,Elastic.Transport.RequestParameters,Elastic.Transport.Diagnostics.OpenTelemetryData&amp;,System.Threading.CancellationToken" />
</match>
</tracerFactory>

</instrumentation>
</extension>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

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

if (instrumentedMethodCall.IsAsync)
var isAsync = instrumentedMethodCall.IsAsync ||
instrumentedMethodCall.InstrumentedMethodInfo.Method.MethodName == "RequestAsync";

if (isAsync)
{
transaction.AttachToAsync();
transaction.DetachFromPrimary(); //Remove from thread-local type storage

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

if (instrumentedMethodCall.IsAsync)
if (isAsync)
{
return Delegates.GetAsyncDelegateFor<Task>(agent, segment, true, InvokeTryProcessResponse, TaskContinuationOptions.ExecuteSynchronously);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.0" Condition="'$(TargetFramework)' == 'net462'" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.9" Condition="'$(TargetFramework)' == 'net471'" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.0.9" Condition="'$(TargetFramework)' == 'net48'" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.9.3" Condition="'$(TargetFramework)' == 'net481'" />
<PackageReference Include="Elastic.Clients.Elasticsearch" Version="8.11.0" Condition="'$(TargetFramework)' == 'net481'" />

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

<!-- Serilog .NET framework references -->
<PackageReference Include="Serilog" Version="1.5.14" Condition="'$(TargetFramework)' == 'net462'" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0


Expand Down Expand Up @@ -174,9 +174,9 @@ private void ValidateOperation(string operationName)

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

var operationDatastoreAgentAttributes = operationDatastoreSpans.FirstOrDefault().AgentAttributes;
var operationDatastoreAgentAttributes = operationDatastoreSpans.FirstOrDefault()?.AgentAttributes;

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

NrAssert.Multiple
(
Expand Down

0 comments on commit 9effb5d

Please sign in to comment.