You need to use the rum agent that's associated with the observability platform that you're going to be ingesting data into. However, keep your eyes peeled on the client instrumentation group for open telemetry. If you want to join the SIG, the details are there on their site as well. And that's really the group that's looking to try and have more of an open standard that's not so vendor locked in. But for the we're going to use the elastic one.
So there's two ways to instrument them. And this tends to be similar patterns across different agents. So you can either use a script tag. Generally, I don't recommend this in an HTML application or in a React app that perhaps is old that you're not touching anymore and you just want to have some basic telemetry included. So you just include the script tag. But generally, the pattern I would recommend is that you install the APM rum extension, sorry, elastic APM rum extension using MPM and then you use the inits and add in the appropriate options.
So the things you need to tell the agent that it's going to send that basically going to categorize the signals that your application is going to send is service name. If you're working on loads of different applications, which was certainly my experience, you need to know which application the signals are corresponding to. And also, if it's the React front end, or those back end services, when we get to front to back tracing. You then got distributed tracing origins, this is needed because by default, the rum agent operates on the same origin policy. So you need to make sure that it's able to add the trace parent header to those HTTP requests going back to back end services, so that you can actually see the full trace, which we'll see later. Then got the server URL, this is the L deployment you're gonna be sending to. And then you've got optional attributes of service version and environment, which well not necessary, you can use them to make sure that maybe you want to compare errors, see how many service versions it goes back to try and identify the source of the problem. Or even if you're doing environmental comparisons, these attributes can be useful to add in.
But we also need to think about the React element because different SPA frameworks behave differently. And sometimes we may need to add particular custom framework integrations alongside, to make sure that we get the appropriate telemetry for our application. And in this particular example, you use the APM run react extension, which is another MPM install. And you use that to access the APM routes component that is then wrapped alongside your react route and your DOM routes. This is as of version six. So if you're using earlier versions, please make sure that you're using the right pattern. It's all covered in the documentation.
Now, just a warning, we need to think about the types of agents that we're adding into our applications. Because if we're not careful, and we're not using the appropriate optimizations, they are going to bloat the build, there's no way around it, doesn't matter if we're using a rum agent, Google Analytics, Hotjar, or something else, these things can really ramp up the bundle size. So make sure you're also following the appropriate instructions for the bundler you're using to make sure you optimize the production version as well. But getting back to what these things give us, they give us all sorts of different metrics are captured.
Comments