Skip to content

Commit

Permalink
Cleanup, minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jun 25, 2024
1 parent c858368 commit 9a0301c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,46 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using NewRelic.Agent.Api;
using NewRelic.Agent.Extensions.Providers.Wrapper;

namespace NewRelic.Providers.Wrapper.AwsSdk
namespace NewRelic.Agent.Extensions.AwsSdk
{
public static class SqsHelper
{
public const string VendorName = "SQS";

private class SqsAttributes
{
public string QueueName;
public string CloudId;
public string Region;
public string QueueName { get; }
public string CloudId { get; }
public string Region { get; }

// https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue
public SqsAttributes(string url)
{
if (string.IsNullOrEmpty(url))
{
return;
}

var parts = url.Split('/');
if (parts.Length < 5)
{
return;
}

CloudId = parts[3];
QueueName = parts[4];

var subdomain = parts[2].Split('.');
if (subdomain.Length < 2)
{
return;
}

// subdomain[0] should always be "sqs"
Region = subdomain[1];
CloudId = parts[3];
QueueName = parts[4];
}
}
public static ISegment GenerateSegment(ITransaction transaction, MethodCall methodCall, string url, MessageBrokerAction action)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

using System;
using System.Linq;
using NewRelic.Agent.Api;
using NewRelic.Agent.Extensions.AwsSdk;
using NewRelic.Agent.Extensions.Providers.Wrapper;

namespace NewRelic.Providers.Wrapper.AwsSdk
Expand Down Expand Up @@ -81,8 +80,13 @@ public AfterWrappedMethodDelegate BeforeWrappedMethod(InstrumentedMethodCall ins
if (insertDistributedTraceHeaders)
{
// This needs to happen at the end
//dynamic webRequest = requestContext.Request;
//SqsHelper.InsertDistributedTraceHeaders(transaction, webRequest);
if (requestContext.Request == null)
agent.Logger.Debug("AwsSdkPipelineWrapper: requestContext.Request is null, unable to insert distributed trace headers.");
else
{
dynamic webRequest = requestContext.Request;
SqsHelper.InsertDistributedTraceHeaders(transaction, webRequest);
}
}

return Delegates.GetDelegateFor(segment);
Expand Down

0 comments on commit 9a0301c

Please sign in to comment.