POST JSON to log event into Application Insights - azure

I need to write a PowerShell Script shell to log an entry into App Insights. I found this post which is useful but I am having a hard time writing to different fields other than the ones being used there. For example I am trying to populate the message field. I don't know the field name in JSON and I don't know where it should go. As you can see in this example I tried placing it everywhere and still did not work. I tried searching for their REST API documentation and still can't find the specs for the JSON.
Can anyone help?
[{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2018-09-20T16:57:16.1771869Z",
"iKey": "1234",
"message": "This is a message",
"tags": {
"ai.operation.name": "Name",
"ai.user.id": "userId",
"ai.cloud.roleInstance": "Machine 1"
},
"data": {
"baseType": "EventData",
"message": "message1",
"baseData": {
"name": "Event from my service",
"message": "message2",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}]

We've been recently trying to achieve the same and didn't find good instructions on the web too, so posting our findings here.
1. API Endpoint
1.1 Authentication
You will need your instrumentation key - see How to get Azure Instrumentation Key for details. That key must be stored in the "iKey" property of the message payload.
1.2 Request
Overall, there seem to be 4 different message types (defined by the "baseType" property) that can be set. All of them need to are sent via POST to the same endpoint
POST https://dc.services.visualstudio.com/v2/track
[ { MESSAGE1 }, { MESSAGE2 }, ... ]
Where the format of each message depends on its type. No authentication headers are needed - the "iKey" field of the message serves as the authentication key.
1.3 Response
The following response is sent in case of success
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"itemsReceived" : 1,
"itemsAccepted" : 1,
"errors":[]
}
Where the "itemsAccepted" property will indicate the number of records accepted by Application Insights.
2. Message Formats
Each individual message in the array must follow one of the following 4 possible JSON formats.
2.1 The "EventData" ("CUSTOM EVENT") message format
This event is shown as the "Custom Event" in the Application Insights. The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2015-05-21T16:43:14.4670675-06:00",
"iKey": "[MyInstrumentationKey]",
"tags": {
},
"data": {
"baseType": "EventData",
"baseData": {
"ver": 2,
"name": "SampleEvent",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}
2.2 The "MessageData" ("TRACE") message format
This event is shown as the "TRACE" in the Application Insights. The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2021-02-25T21:35:45.0000000Z",
"iKey": "[MyInstrumentationKey]",
"tags":{
},
"data": {
"baseType": "MessageData",
"baseData": {
"ver": 2,
"message": "Simple Trace Log Message",
"severityLevel": 2,
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}
severityLevel meaning
level 0 = "Verbose"
level 1 = "Information"
level 2 = "Warning"
level 3 = "Error"
level 4 = "Critical"
2.3 The "MetricData" message format
The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2021-02-25T21:35:45.0000000Z",
"iKey": "[MyInstrumentationKey]",
"tags": {
},
"data": {
"baseType": "MetricData",
"baseData": {
"ver": 2,
"metrics": [
{
"name": "BasicMetric",
"kind": "Measurement",
"value": 42
}
],
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
}
}
}
}
2.4 The "ExceptionData" message format
The following payload must be used:
{
"name": "Microsoft.ApplicationInsights.Event",
"time": "2021-02-25T21:35:45.0000000Z",
"iKey": "[MyInstrumentationKey]",
"tags": {
},
"data": {
"baseType": "ExceptionData",
"baseData": {
"ver": 2,
"handledAt": "UserCode",
"properties": {
"x": "value x",
"y": "value y",
"z": "value z"
},
"exceptions": [
{
"id": 26756241,
"typeName": "System.Exception",
"message": "Something bad has happened!",
"hasFullStack": true,
"parsedStack": [
{
"level": 0,
"method": "Console.Program.Main",
"assembly": "Console, Version=1.0",
"fileName": "/ApplicationInsights/Test.cs",
"line": 42
}
]
}
]
}
}
}

You can put the message in the properties:{}.
After execute the powershell script, go to azure portal, you should see the message field there:
But if you wanna add a field in the Custom Event Properties section, there seams no way to do it.

Related

Need an expression to use in an azure logic app in-order to fetch an element of a JSON

I have a JSON Content in my Logic App. I need to fetch only a particular element (value of commitId) from the JSON and not all attributes. Can you please help me to write an appropriate expression !
{
"count": 1,
"value": [
{
"commitId": "zzzzzzzzzzzzzzzzzzzz",
"author": {
"name": "mahesh",
"email": "mahesh#xyz.com",
"date": "2020-03-27T09:43:03Z"
},
"committer": {
"name": "mahesh",
"email": "mahesh#xyz.com",
"date": "2020-03-27T09:43:03Z"
},
"comment": "Added task markdown file.",
"changeCounts": {
"Add": 1,
"Edit": 0,
"Delete": 0
},
"changes": [
{
"sourceServerItem": "/Books",
"changeType": "edit"
}
],
"url": "https://dev.azure.com/company/aaaabbbbbbb/_apis/git/repositories/ccccddddd/commits/eeeeeefffff",
"remoteUrl": "https://dev.azure.com/company/DataEngineering/_git/Test/commit/aaabbbbccccdddd"
}
]
}
You just need to use "Parse JSON" action to parse your json data and then please refer to the expression below:
The whole expression in the screenshot above is:
body('Parse_JSON')?['value'][0]?['commitId']
Then we can get the value of commitId after running it.

How to add a new top-level entity (to rest web service endpoint) using acumatica screenID?

Acumatica cloud ERP has a screen that displays failed push notifications (screenID = SM502000). I have created a new Web Services Endpoint, and added a new top-level entity from that screenID. However, no matter what fields I try to add, I get a variation on this error:
Optimization cannot be performed.The following fields cause the error:\r\nSelected: View FailedToSend has BQL delegate\r\n
Edit. I was able to create a REST end-point to fetch the results using a generic inquiry. Here is the JSON returned:
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 1,
"note": null,
"Result": [
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 1,
"note": null,
"Date": {
"value": 637167021636873690
},
"DateTimeStamp": {
"value": "2020-02-07T19:56:03.687369+00:00"
},
"DestinationNamePushNotifications_hookId": {
"value": "test"
},
"DestinationNamePushNotifications_hookId_description": {
"value": "test"
},
"Error": {
"value": "Send to target test failed. Message: WebHook returns not success code: NotFound; Message: Tunnel webhook.local not found"
},
"NotificationBody": {
"value": "..."
},
"PushNotifications_selected": {},
"Selected": {
"value": false
},
"SourceName": {
"value": "SO-SalesOrder"
},
"TransactionId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"custom": {},
"files": []
},
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 2,
"note": null,
"Date": {
"value": 637167021636873690
},
"DateTimeStamp": {
"value": "2020-02-07T19:56:03.687369+00:00"
},
"DestinationNamePushNotifications_hookId": {
"value": "test"
},
"DestinationNamePushNotifications_hookId_description": {
"value": "test"
},
"Error": {
"value": "Send to target test failed. Message: WebHook returns not success code: NotFound; Message: Tunnel webhook.local not found"
},
"NotificationBody": {
"value": "..."
},
"PushNotifications_selected": {},
"Selected": {
"value": false
},
"SourceName": {
"value": "SO-SalesOrder"
},
"TransactionId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"custom": {},
"files": []
}
]
}
Here's a good tutorial for using GI to access data via API:
https://www.acumatica.com/blog/contract-based-apis-in-generic-inquiries/
Try retrieving the records one by one with a REST filter in the URL. The issue is that the target graph you added has a data view (FailedToSend) which uses a data view delegate.
Because data view delegates can be slower than no delegates the API refuses to return more than one record as an optimization.

Node.js: Sending Cucumber JSON results to Jira's Xray - jira-client-xray gives HTTP 405 error

I'm struggling 5th day with sending test results to Jira. Our Jira has latest Xray plugin.
I use Node.js for test automation. I went easiest way to try Xray's capability of swallowing test automation results: 'jira-client-xray' dependency + Cucumber test.
In Jira I have Test Execution (id is KELLO-2426), what includes 1 Test (id is KELLO-2427) with Cucumber steps - Jira_Xray_Auto_Test.PNG.
I have 1 feature file - Feature_file.PNG.
After running the test/feature I got JSON-file with results:
[
{
"keyword": "Feature",
"description": "",
"line": 1,
"name": "Sample Snippets test",
"uri": "Can not be determined",
"tags": [],
"elements": [
{
"keyword": "Scenario",
"description": "",
"name": "open URL",
"tags": [
{
"name": "#KELLO:2426",
"location": {
"line": 6,
"column": 5
}
}
],
"id": "sample-snippets-test;open-url",
"steps": [
{
"arguments": [],
"keyword": "Before",
"name": "Hook",
"result": {
"status": "passed",
"duration": 1301000000
},
"line": "",
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "Given",
"name": "the page url is not \"http://webdriverjs.christian-bromann.com/\"",
"result": {
"status": "passed",
"duration": 257000000
},
"line": 8,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "And",
"name": "I open the url \"http://webdriverjs.christian-bromann.com/\"",
"result": {
"status": "passed",
"duration": 1221000000
},
"line": 9,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "Then",
"name": "I expect that the url is \"http://webdriverjs.christian-bromann.com/\"",
"result": {
"status": "passed",
"duration": 244000000
},
"line": 10,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "And",
"name": "I expect that the url is not \"http://google.com\"",
"result": {
"status": "passed",
"duration": 205000000
},
"line": 11,
"match": {
"location": "can not be determined with webdriver.io"
}
},
{
"arguments": [],
"keyword": "After",
"name": "Hook",
"result": {
"status": "passed",
"duration": 186000000
},
"line": "",
"match": {
"location": "can not be determined with webdriver.io"
}
}
]
}
],
"id": "sample-snippets-test",
"metadata": {
"browser": {
"name": "chrome",
"version": "72.0.3626.121"
},
"device": "Device name not known",
"platform": {
"name": "Platform name not known",
"version": "Version not known"
}
}
}
]
Next, I have 'jira.client.xray.js' file, where sending the results is written:
var JiraApiWithXray = require('jira-client-xray');
// Initialize
var jiraXray = new JiraApiWithXray({
strictSSL: false,
protocol: 'https',
username: 'your_username',
password: 'your_password',
host: 'your_host',
apiVersion: '1.0' //Check version from DevTools -> Network tab
});
const testExecResults = './results/sample-snippets-test.1574077621820.json';
try {
jiraXray.importExecResultsFromCucumber(testExecResults).then(function (testExecIssueId) {});
} catch(ex) {
console.log('Error:');
console.log(ex);
}
Initiating delivery of the test results by command node jira.client.xray.js from projects root directory gives me the following error:
UnhandledPromiseRejectionWarning: StatusCodeError: 405 - undefined
What is wrong? Suggest me please.
Yours sincerely,
JS comrade
Here shows the error you are receiving
https://restfulapi.net/http-status-codes/
That would lead me to believe it is a problem with your request being sent. My initial thoughts are testExecResults is in the wrong structure based on the documentation https://www.npmjs.com/package/jira-client-xray
Please post the request being sent.

There was a problem with the requested skill's response using template, Alexa skill using template directive

I have an issue with alexa skill in node.
i'm making an skill that connect with db via HTTS.response
everything works fine until I want to show the results in a template.
this its the response.
{
"outputSpeech": {
"type": "PlainText",
"text": "That's sound good. Your search is Property Type: residential - City:Petersburg - Zip Code:33715 - Bedrooms:2 - Price: $100000"
},
"directives": [
{
"type": "Display.RenderTemplate",
"template": {
"type": "ListTemplate2",
"token": "ShowHomeView",
"backButton": "hidden",
"backgroundImage": {
"contentDescription": "",
"sources": [
{
"url": "https://s3.amazonaws_com/ask-samples-resources/berryImages/main_blur2.png"
}
]
},
"title": "Search Results",
"listItems": [
{
"token": 1,
"image": "https://mydomain/images/fine_arts-1550.jpg",
"textContent": "This is my list item 1"
},
{
"token": 2,
"image": "https://mydomain/images/fine_arts-1550.jpg",
"textContent": "This is my list item 2"
},
{
"token": 3,
"image": "https://mydomain/images/fine_arts-1550.jpg",
"textContent": "This is my list item 3"
}
]
}
},
{
"type": "Hint",
"hint": {
"type": "PlainText",
"text": " select number two. "
}
}
],
"shouldEndSession": false
}
and in alexa console say:
There was a problem with the requested skill's response
and in the device log say.
"descriptiveText": [
"Request Identifier: amzn1.echo-api.request.f6d03bab-05b2-449f-877b-b58f8e28274b",
"",
"The skill returned an invalid response"
],
What could be causing this error?
thnks in advance

Acumatica API insert data "Bad Request"

I'm trying to insert a stock item into Acumatica using the API, but I'm getting a 400 error - Bad Request. I'm using HttpClient to login, retrieve a stock item, and send the insert request. All is working except the insert request. I have tried the following url (including expand parameter):
http://localhost/AcumaticaERP/entity/Default/6.00.001/StockItem?$expand=Attributes,CrossReferences,UOMConversions,VendorDetails,WarehouseDetails
... and also the following url (without expand parameter)
http://localhost/AcumaticaERP/entity/Default/6.00.001/StockItem
I'm calling via HttpClient PutAsync, passing in the URLs mentioned above, and the data is JSON from a stock item retrieved with the API, and which doesn't exist in the current db.
client.PutAsync(insertUrl, new StringContent(data, Encoding.UTF8, "application/json")).Result;
Any ideas what I'm missing?
NEW DETAILS:
After further debugging and testing with Postman, the error from the PUT seems to be "Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1." The JSON was taken directly from a GET though, so I'm not sure what the problem could be. Below is the JSON returning an error from the PUT.
[
{
"id": "cc27ce56-6302-4f1b-97aa-49cca3ed32ea",
"rowNumber": 1,
"note": "",
"Attributes": [],
"BaseUOM": {
"value": "EA"
},
"CrossReferences": [],
"DefaultIssueLocationID": {
"value": "R1S1"
},
"DefaultReceiptLocationID": {
"value": "RECEIVING"
},
"DefaultWarehouseID": {
"value": "WHOLESALE"
},
"Description": {
"value": "tonyitem2"
},
"ImageUrl": {},
"InventoryID": {
"value": "TONYITEM2"
},
"IsAKit": {
"value": false
},
"ItemClass": {
"value": "CONSUMER 300TOYS"
},
"ItemStatus": {
"value": "Active"
},
"ItemType": {
"value": "Finished Good"
},
"LastModified": {
"value": "2018-08-03T12:09:19.907-04:00"
},
"LotSerialClass": {
"value": "NOTTRACKED"
},
"PurchaseUOM": {
"value": "EA"
},
"SalesUOM": {
"value": "EA"
},
"UOMConversions": [],
"VendorDetails": [],
"Volume": {
"value": 0
},
"WarehouseDetails": [
{
"id": "3ca5ea4c-c651-498e-8e6c-49119481982c",
"rowNumber": 1,
"note": "",
"DefaultIssueLocationID": {
"value": "R1S1"
},
"DefaultReceiptLocationID": {
"value": "RECEIVING"
},
"IsDefault": {
"value": true
},
"QtyOnHand": {
"value": 0
},
"WarehouseID": {
"value": "WHOLESALE"
},
"custom": {},
"files": []
}
],
"Weight": {
"value": 0
},
"custom": {},
"files": []
}
]
I also tried removing the brackets surrounding the JSON, and then the error is:
"No entity satisfies the condition.". Could the issue be that the ids have GUIDs, but I'm trying to do an insert? How do you indicate that the PUT is supposed to be inserting?
I finally got the PUT to insert. What finally worked was removing the wrapping braces "[" and "]" around the entire JSON; plus removing all "id", "rowNumber", "custom", and "files" fields, and all empty collections (e.g. Attributes, CrossReferences) in my JSON. I'm not sure which of these being removed resolved it and allowed me to insert, but it finally worked.
It's real unfortunate that the JSON you retrieve via GET can't be inserted via PUT without stripping all of this out first though. What a pain.

Resources