Workflows - convert JSON into the BizEvents format

Hello Community,

I am working on creating a Dynatrace workflow where I start with sample JSON data and need to convert that JSON into the BizEvents format so it can be ingested into Grail.

Could you please help me with the correct JavaScript structure for this conversion? Here’s the sample JSON I am working with and the code I have so far:

javascriptBecause  when i am ingesting and fetching bizevents through DQL  I am getting No records found in the dashboards
The approach I have used is - Trigger->Javascript->Ingest Business events

<span>function</span> <span>main</span><span>(</span><span>) </span><span>{
  </span><span>// Sample JSON data</span>
  <span>const</span> <span>data </span><span>= </span><span>{
    </span><span>requestId</span><span>: </span><span>"12345"</span><span>,
    </span><span>dateTime</span><span>: </span><span>"2024-04-22T14:30:00.000Z"</span><span>,
    </span><span>totalProxies</span><span>: </span><span>100</span><span>,
    </span><span>proxyList</span><span>: </span><span>[
      </span><span>{
        </span><span>proxyName</span><span>: </span><span>"ddd"</span><span>,
        </span><span>environment</span><span>: </span><span>"hhh"</span><span>,
        </span><span>revision</span><span>: </span><span>1</span><span>,
        </span><span>created</span><span>: </span><span>"2024-04-22T14:30:00.000Z"</span><span>,
        </span><span>lastModified</span><span>: </span><span>"2024-04-22T14:30:00.000Z"</span><span>,
        </span><span>basePath</span><span>: </span><span>"/basePath"</span><span>,
        </span><span>deployState</span><span>: </span><span>true</span><span>,
        </span><span>TargetServer</span><span>: </span><span>[</span><span>"Server1"</span><span>, </span><span>"Server2"</span><span>],
        </span><span>targetEndpoint</span><span>: </span><span>[</span><span>"/Service1"</span><span>, </span><span>"/Service2"</span><span>],
        </span><span>sharedFlows</span><span>: </span><span>[</span><span>"sgg"</span><span>, </span><span>"sgg"</span><span>]
      </span><span>}
    </span><span>]
  </span><span>};

  </span><span>// Convert each proxy into a BizEvent</span>
  <span>return</span> <span>data.</span><span>proxyList</span><span>.</span><span>map</span><span>(</span><span>proxy =></span> <span>({
    </span><span>"event.provider"</span><span>: </span><span>"apigee"</span><span>,
    </span><span>"event.type"</span><span>: </span><span>"apigee.proxy.metadata"</span><span>,
    </span><span>"event.category"</span><span>: </span><span>"inventory"</span><span>,
    </span><span>attributes</span><span>: </span><span>{
      </span><span>bucket</span><span>: </span><span>"test-poc"</span><span>,   </span><span>// custom marker</span>
      <span>requestId</span><span>: </span><span>data.</span><span>requestId</span><span>,
      </span><span>dateTime</span><span>: </span><span>data.</span><span>dateTime</span><span>,
      </span><span>totalProxies</span><span>: </span><span>data.</span><span>totalProxies</span><span>,
      </span><span>proxyName</span><span>: </span><span>proxy.</span><span>proxyName</span><span>,
      </span><span>environment</span><span>: </span><span>proxy.</span><span>environment</span><span>,
      </span><span>revision</span><span>: </span><span>proxy.</span><span>revision</span><span>,
      </span><span>created</span><span>: </span><span>proxy.</span><span>created</span><span>,
      </span><span>lastModified</span><span>: </span><span>proxy.</span><span>lastModified</span><span>,
      </span><span>basePath</span><span>: </span><span>proxy.</span><span>basePath</span><span>,
      </span><span>deployState</span><span>: </span><span>proxy.</span><span>deployState</span><span>,
      </span><span>targetServers</span><span>: </span><span>proxy.</span><span>TargetServer</span><span>,
      </span><span>targetEndpoints</span><span>: </span><span>proxy.</span><span>targetEndpoint</span><span>,
      </span><span>sharedFlows</span><span>: </span><span>proxy.</span><span>sharedFlows</span>
    <span>}
  </span><span>}));</span><span>}</span>

:small_blue_diamond: My Questions

  1. Is this the correct way to structure BizEvents JSON in a workflow JavaScript step?
  2. Do I need to add or change any mandatory fields for Grail ingestion?
  3. Are there best practices for handling multiple proxies in the array (e.g., batching vs individual events)?

Thanks in advance for your guidance!

Hi,

Since you are in Managed… Are workflows available in your environment?

Best regards

Yes workflows are available in my environment . I am working on staging now

Hi,

I was not aware workflows were available in Managed environment… Are you in SaaS?

Best regards

It is definitely SaaS. Workflows are SaaS only feature.

@tmehta3 I’m not sure what issue you are trying to solve. Maybe a different option of raising business events - (in OpenPipeline) may fit your case better. Be aware that workflows have some execution limitations and you may run in throttling issues if your workflow is executed too often.

For an example to raise a bizevent from JavaScript in the platform, see Classic environment v2 | Dynatrace Developer (example included).
As then it comes to the data:

  • You need the mandatory fields - event.provider and event.type at least with event.category being recommended
  • Follow the semantic dictionary - Business Analytics — Dynatrace Docs and I recommend following that in general for your attributes Global field reference — Dynatrace Docs (typically fields such as url.path for example)
  • If you really need workflow and you want to create multiple events from a single execution, send multiple events in a batch

Hi there,

I’ve checked this on my own demo environment, I am able to ingest this event via:

/*
* This function will run in the DYNATRACE JavaScript runtime.
* For information visit https://dt-url.net/functions-help
*/
import { businessEventsClient } from '@dynatrace-sdk/client-classic-environment-v2';

export default async function () {

  // Sample JSON data
  const data = {
    requestId: "12345",
    dateTime: "2024-04-22T14:30:00.000Z",
    totalProxies: 100,
    proxyList: [
      {
        proxyName: "ddd",
        environment: "hhh",
        revision: 1,
        created: "2024-04-22T14:30:00.000Z",
        lastModified: "2024-04-22T14:30:00.000Z",
        basePath: "/basePath",
        deployState: true,
        TargetServer: ["Server1", "Server2"],
        targetEndpoint: ["/Service1", "/Service2"],
        sharedFlows: ["sgg", "sgg"]
      }
    ]}

  console.log(data);

  // Convert each proxy into a BizEvent
  const mapEvent =  data.proxyList.map(proxy => ({
    "event.provider": "apigee",
    "event.type": "apigee.proxy.metadata",
    "event.category": "inventory",
    "attributes": {
      bucket: "test-poc",   // custom marker
      requestId: data.requestId,
      dateTime: data.dateTime,
      totalProxies: data.totalProxies,
      proxyName: proxy.proxyName,
      environment: proxy.environment,
      revision: proxy.revision,
      created: proxy.created,
      lastModified: proxy.lastModified,
      basePath: proxy.basePath,
      deployState: proxy.deployState,
      targetServers: proxy.TargetServer,
      targetEndpoints: proxy.targetEndpoint,
      sharedFlows: proxy.sharedFlows
    }
  }));
  console.log(mapEvent)

businessEventsClient
  .ingest({
    body: mapEvent,
    type: 'application/json',
  })
  .then(() => console.log('Event ingested'))
  .catch((e) => console.error('Failed to ingest event: ' + e));

}

The event pops up in my environment, could you verify whether you are doing the same steps?

Hi,

I have just moved this thread to “Automations” thread instead of Managed.

Best regards