-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2204 from newrelic/sqs-distributed-trace
Sqs distributed trace
- Loading branch information
Showing
17 changed files
with
526 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ion/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSBatchRequestHeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.newrelic.utils; | ||
|
||
import com.amazonaws.services.sqs.model.MessageAttributeValue; | ||
import com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry; | ||
import com.newrelic.api.agent.HeaderType; | ||
import com.newrelic.api.agent.Headers; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class SQSBatchRequestHeaders implements Headers { | ||
private final SendMessageBatchRequestEntry requestEntry; | ||
|
||
public SQSBatchRequestHeaders(SendMessageBatchRequestEntry re) { | ||
requestEntry = re; | ||
} | ||
|
||
@Override | ||
public HeaderType getHeaderType() { | ||
return HeaderType.MESSAGE; | ||
} | ||
|
||
@Override | ||
public String getHeader(String name) { | ||
Map<String, MessageAttributeValue> attributes = requestEntry.getMessageAttributes(); | ||
if (attributes != null) { | ||
MessageAttributeValue value = attributes.get(name); | ||
if (value != null) { | ||
String dataType = value.getDataType(); | ||
if (dataType.equalsIgnoreCase("String")) { | ||
String stringValue = value.getStringValue(); | ||
if (stringValue != null) { | ||
return stringValue; | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<String> getHeaders(String name) { | ||
List<String> list = new ArrayList<String>(); | ||
String value = getHeader(name); | ||
if (value != null && !value.isEmpty()) { | ||
list.add(value); | ||
} | ||
return list; | ||
} | ||
|
||
@Override | ||
public void setHeader(String name, String value) { | ||
if (requestEntry != null) { | ||
requestEntry.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); | ||
} | ||
} | ||
|
||
@Override | ||
public void addHeader(String name, String value) { | ||
if (requestEntry != null) { | ||
requestEntry.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<String> getHeaderNames() { | ||
if (requestEntry != null) { | ||
Map<String, MessageAttributeValue> attributes = requestEntry.getMessageAttributes(); | ||
if (attributes != null) { | ||
return attributes.keySet(); | ||
} | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public boolean containsHeader(String name) { | ||
return getHeaderNames().contains(name); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...entation/aws-java-sdk-sqs-1.10.44/src/main/java/com/newrelic/utils/SQSRequestHeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.newrelic.utils; | ||
|
||
import com.amazonaws.services.sqs.model.MessageAttributeValue; | ||
import com.amazonaws.services.sqs.model.SendMessageRequest; | ||
import com.newrelic.api.agent.HeaderType; | ||
import com.newrelic.api.agent.Headers; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
public class SQSRequestHeaders implements Headers { | ||
private final SendMessageRequest request; | ||
|
||
public SQSRequestHeaders(SendMessageRequest req) { | ||
request = req; | ||
} | ||
|
||
@Override | ||
public HeaderType getHeaderType() { | ||
return HeaderType.MESSAGE; | ||
} | ||
|
||
@Override | ||
public String getHeader(String name) { | ||
Map<String, MessageAttributeValue> messageAttributes = request.getMessageAttributes(); | ||
if (messageAttributes != null) { | ||
MessageAttributeValue value = messageAttributes.get(name); | ||
if (value != null && value.getDataType().equalsIgnoreCase("string")) { | ||
return value.getStringValue(); | ||
} | ||
} | ||
Map<String, String> customRequestHeaders = request.getCustomRequestHeaders(); | ||
if (customRequestHeaders != null) { | ||
return customRequestHeaders.get(name); | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Collection<String> getHeaders(String name) { | ||
String value = getHeader(name); | ||
if (value != null) { | ||
return Collections.singletonList(value); | ||
} | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public void setHeader(String name, String value) { | ||
if (request != null) { | ||
Map<String, MessageAttributeValue> existingAttributes = request.getMessageAttributes(); | ||
if (!existingAttributes.containsKey(name)) { | ||
request.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void addHeader(String name, String value) { | ||
if (request != null) { | ||
Map<String, MessageAttributeValue> existingAttributes = request.getMessageAttributes(); | ||
if (!existingAttributes.containsKey(name)) { | ||
request.addMessageAttributesEntry(name, new MessageAttributeValue().withDataType("String").withStringValue(value)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public Collection<String> getHeaderNames() { | ||
Map<String, MessageAttributeValue> messageAttributes = request.getMessageAttributes(); | ||
return messageAttributes.keySet(); | ||
} | ||
|
||
@Override | ||
public boolean containsHeader(String name) { | ||
return getHeaderNames().contains(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.