Open Q&A
If there's no good subforum for your question - ask it here!
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Request attributes: Pick a value from comma separated values

ashik_h2k
Visitor

Currently In Distributed Tracing, I can see the value as below, under Request attributes, using the below mentioned payload. 
1. [key1,key2,key3] when "argumentIndex": 1
2. [value1,value2,value3] when "argumentIndex": 2

Please advise on how I can get the value of "Request-attributes-1" as only "value2"?

 

{
"name": "Request-attributes-1",
"enabled": true,
"dataType": "STRING",
"dataSources": [
{
"enabled": true,
"source": "METHOD_PARAM",
"technology": "JAVA",
"methods": [
{
"method": {
"visibility": "PUBLIC",
"modifiers": [
"ABSTRACT"
],
"className": "javax.class1.class2",
"methodName": "setAttribute",
"argumentTypes": [
"java.lang.String",
"java.lang.Object"
],
"returnType": "void"
},
"capture": "ARGUMENT",
"argumentIndex": X,
"deepObjectAccess": "toString().trim()"
}
]
}
],
"normalization": "ORIGINAL",
"aggregation": "ALL_DISTINCT_VALUES",
"confidential": false,
"skipPersonalDataMasking": false
}
3 REPLIES 3

sujit_k_singh
Champion

Hi @ashik_h2k 

The setAttribute(String key, Object value) method takes the key as argument 1 and value as argument 2. The issue is that with argumentIndex: 2 you're capturing all values from every setAttribute call, not just the one where key = "key2".

You need to add a condition on your data source so it only captures argument 2 (value) when argument 1 (key) matches your desired key.

Add valueCondition and conditionArgumentIndex to your payload:

{
"name": "Request-attributes-1",
"enabled": true,
"dataType": "STRING",
"dataSources": [
{
"enabled": true,
"source": "METHOD_PARAM",
"technology": "JAVA",
"methods": [
{
"method": {
"visibility": "PUBLIC",
"modifiers": ["ABSTRACT"],
"className": "javax.class1.class2",
"methodName": "setAttribute",
"argumentTypes": ["java.lang.String", "java.lang.Object"],
"returnType": "void"
},
"capture": "ARGUMENT",
"argumentIndex": 2,
"deepObjectAccess": "toString().trim()"
}
],
"valueCondition": {
"negate": false,
"operator": "EQUALS",
"value": "key2"
},
"scope": {
"tagOfProcessGroup": null
},
"parameterName": "key2",
"conditionSource": "METHOD_PARAM",
"conditionArgumentIndex": 1
}
],
"normalization": "ORIGINAL",
"aggregation": "FIRST",
"confidential": false,
"skipPersonalDataMasking": false
}

This way you'll only get "value2" when the key is "key2".

Thanks,

Sujit

Dynatrace Professional Certified

Thanks @sujit_k_singh , I get the following error

{
"error": {
"code": 400,
"message": "Constraints violated.",
"constraintViolations": [
{
"path": "dataSources[0].parameterName",
"message": "Incompatible with attribute type.",
"parameterLocation": "PAYLOAD_BODY",
"location": null
}
]
}
}

 

When I look at https://docs.dynatrace.com/docs/dynatrace-api/configuration-api/service-api/request-attributes-api/p..., it is mentioned parameterName Required if the source is one of the following: POST_PARAMETER, GET_PARAMETER, REQUEST_HEADER, RESPONSE_HEADER, CUSTOM_ATTRIBUTE, but parameterName is METHOD_PARAM in the above case.

Hi @ashik_h2k 

Ahhh .. my bad, right — parameterName is incompatible with METHOD_PARAM source type. That field is only valid for POST_PARAMETER, GET_PARAMETER, REQUEST_HEADER, RESPONSE_HEADER, or CUSTOM_ATTRIBUTE sources.

Simply remove the "parameterName": "key2" line from the payload. The filtering is handled entirely by valueCondition + conditionArgumentIndex. Here's the corrected version:

{
"name": "Request-attributes-1",
"enabled": true,
"dataType": "STRING",
"dataSources": [
{
"enabled": true,
"source": "METHOD_PARAM",
"technology": "JAVA",
"methods": [
{
"method": {
"visibility": "PUBLIC",
"modifiers": ["ABSTRACT"],
"className": "javax.class1.class2",
"methodName": "setAttribute",
"argumentTypes": ["java.lang.String", "java.lang.Object"],
"returnType": "void"
},
"capture": "ARGUMENT",
"argumentIndex": 2,
"deepObjectAccess": "toString().trim()"
}
],
"valueCondition": {
"negate": false,
"operator": "EQUALS",
"value": "key2"
},
"scope": {
"tagOfProcessGroup": null
},
"conditionSource": "METHOD_PARAM",
"conditionArgumentIndex": 1
}
],
"normalization": "ORIGINAL",
"aggregation": "FIRST",
"confidential": false,
"skipPersonalDataMasking": false
}

The parameterName field was the culprit causing the 400 error. Removing it should resolve the constraint violation.

Thanks,

Sujit

Dynatrace Professional Certified

Featured Posts