<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rahul Ranjan</title>
    <description>The latest articles on DEV Community by Rahul Ranjan (@rranjan).</description>
    <link>https://dev.to/rranjan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1932653%2F23475450-7afa-4146-9a4a-fa2054635e4f.jpg</url>
      <title>DEV Community: Rahul Ranjan</title>
      <link>https://dev.to/rranjan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rranjan"/>
    <language>en</language>
    <item>
      <title>Elastic RUM (Real User Monitoring) with Open Telemetry (OTel)</title>
      <dc:creator>Rahul Ranjan</dc:creator>
      <pubDate>Sun, 18 Aug 2024 06:53:33 +0000</pubDate>
      <link>https://dev.to/rranjan/elastic-rum-real-user-monitoring-with-open-telemetry-otel-3nbg</link>
      <guid>https://dev.to/rranjan/elastic-rum-real-user-monitoring-with-open-telemetry-otel-3nbg</guid>
      <description>&lt;p&gt;This article continues the OpenTelemetry with Elastic Observability article, covering “How to set up the OpenTelemetry demo with Elastic Observability” using Docker Compose or Kubernetes.&lt;/p&gt;

&lt;p&gt;Elastic real user monitoring, or RUM, captures user interactions with the web browser and provides a detailed view of the “real user experience” of your web applications from a performance perspective. &lt;/p&gt;

&lt;p&gt;Elastic’s RUM Agent is a JavaScript Agent, which means it supports any JavaScript-based application. RUM can provide valuable insight into your applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of RUM (Real User Monitoring)&lt;/strong&gt;&lt;br&gt;
RUM performance data can help you identify bottlenecks and discover how site performance issues affect your visitors’ experience&lt;br&gt;
User-agent information captured by RUM enables you to identify the browsers, devices, and platforms most used by your customers so that you can make informed optimizations to your application&lt;br&gt;
Along with location information, individual user performance data from RUM helps you understand the regional performance of your website worldwide&lt;br&gt;
RUM provides insight and measurement for your application’s service level agreements (SLA)&lt;br&gt;
RUM gathers information on customer visits and clicks behavior over time that can be useful for development teams to identify the impact of new features.&lt;/p&gt;

&lt;p&gt;We will cover step-by-step mechanisms for enabling RUM(Real User Monitoring) in the application and then monitor it in Elasticsearch Observability.&lt;/p&gt;

&lt;p&gt;Download and Install the application from Github Repo either on Docker or Kubernetes and configure it as described in OpenTelemetry with Elastic Observability.&lt;/p&gt;

&lt;p&gt;Once the application is up and running, Go to Your deployment → Integration→APM →RumJS→copy configuration as seen in below image.&lt;br&gt;
Copy the below configuration settings for setting up the Agent as a dependency.&lt;/p&gt;

&lt;p&gt;You can install the Agent as a dependency on your application with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @elastic/apm-rum --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Agent can then be initialized and configured in your application like below. Refer to the integration documentation for more details.&lt;/p&gt;

&lt;p&gt;Alternatively, copy the below configuration settings for setting up the Agent with Script Tags.&lt;/p&gt;

&lt;p&gt;Now we will configure the frontend application with these settings to RUM.&lt;/p&gt;

&lt;p&gt;Navigate to your application service folder(&lt;code&gt;opentelemetry-demo/src/frontend/Dockerfile)&lt;/code&gt; and update the  docker file with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;RUN npm install @elastic/apm-rum --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Navigate to the application(frontend) service folder (opentelemetry-demo/src/frontend/pages/_app.tsx) and update the configuration for RUM.&lt;br&gt;
You can customize the service name and environment parameters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//CONFIGURE RUM AGENT
import { init as initApm } from '@elastic/apm-rum';
if (typeof window !== 'undefined'){
   initApm({
       serviceName: 'otel-frontend',    
       serverUrl: '&amp;lt;url&amp;gt;',
       serviceVersion: '',
       environment: 'demo'
   });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Service name: It represents your application in the APM UI. &lt;/p&gt;

&lt;p&gt;Service version: This is the version of your application. This version number is also used by the APM server to find the right source map. &lt;/p&gt;

&lt;p&gt;Server URL: This is the APM server URL. Note that the APM server URL is normally accessible from the public internet because your RUM agent reports data to it from end-user browsers on the internet.&lt;/p&gt;

&lt;p&gt;environment: This is helpful in a shared environment where multiple users are accessing for better filtering.&lt;br&gt;
Login to Kibana and then navigate to the User Experience section of Observability and analyze the RUM data and play around with the available metrics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iy2dj5zginjkv9aqxvv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7iy2dj5zginjkv9aqxvv.png" alt="Image description" width="800" height="696"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdjpc1szmsaz7ljkg819.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbdjpc1szmsaz7ljkg819.png" alt="Image description" width="800" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h8kct511f5l9psoy2np.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h8kct511f5l9psoy2np.png" alt="Image description" width="800" height="416"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Reference: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/pulse/opentelemetry-elastic-observability-rahul-ranjan-3l6bc/" rel="noopener noreferrer"&gt;https://www.linkedin.com/pulse/opentelemetry-elastic-observability-rahul-ranjan-3l6bc/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://opentelemetry.io/docs/demo/" rel="noopener noreferrer"&gt;https://opentelemetry.io/docs/demo/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.elastic.co/guide/en/observability/8.14/apm-configuration-rum.html" rel="noopener noreferrer"&gt;https://www.elastic.co/guide/en/observability/8.14/apm-configuration-rum.html&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>kubernetes</category>
      <category>elasticsearch</category>
      <category>devops</category>
    </item>
    <item>
      <title>OpenTelemetry with Elastic Observability</title>
      <dc:creator>Rahul Ranjan</dc:creator>
      <pubDate>Fri, 16 Aug 2024 15:21:49 +0000</pubDate>
      <link>https://dev.to/rranjan/opentelemetry-with-elastic-observability-4oik</link>
      <guid>https://dev.to/rranjan/opentelemetry-with-elastic-observability-4oik</guid>
      <description>&lt;p&gt;OpenTelemetry is an open-source framework for observability that, when combined with Elastic Observability, provides powerful insights into distributed systems. It enables organizations to efficiently monitor, troubleshoot, and optimize their applications. In this article, we will provide you with a detailed guide on how to set up an OpenTelemetry demo with Elastic Observability. We will cover essential steps, configurations, and best practices that will help you leverage the full potential of observability in your environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding OpenTelemetry and Elastic Observability:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;OpenTelemetry:&lt;br&gt;
OpenTelemetry is a project under the Cloud Native Computing Foundation (CNCF) that aims to provide a cohesive approach to instrument, generate, collect, and export telemetry data, which includes metrics, traces, and logs, from software applications. It offers libraries for instrumenting code in various programming languages and provides standardized APIs to capture telemetry data from different components of distributed systems.&lt;/p&gt;

&lt;p&gt;Elastic Observability:&lt;br&gt;
Elastic Observability is a complete solution for observability provided by Elastic. It provides integrated tools for monitoring, logging, and tracing distributed applications. The solution includes Elastic APM (Application Performance Monitoring), Elastic Logs, and Elastic Metrics, all of which are seamlessly integrated within the Elastic Stack.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Setup Details:&lt;/strong&gt;&lt;br&gt;
This doc will cover both &lt;code&gt;How to set up the OpenTelemetry demo with Elastic Observability&lt;/code&gt; using &lt;em&gt;Docker compose&lt;/em&gt; or &lt;em&gt;Kubernetes&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download the source code of the application from GitHub Repo.&lt;/strong&gt;&lt;br&gt;
Download your application on a Kubernetes cluster in your cloud service of choice or local Kubernetes platform. First, clone the directory locally. Make sure you have kubectl and helm also installed locally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/elastic/opentelemetry-demo.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OTEL_EXPORTER_OTLP_ENDPOINT is Elastic's APM Server
OTEL_EXPORTER_OTLP_HEADERS Elastic Authorization
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under Integrations-&amp;gt;APM in your Elastic cloud, find these values in OpenTelemetry setup instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Docker compose&lt;/strong&gt;&lt;br&gt;
Start a free trial on Elastic Cloud and copy the endpoint and secretToken from the Elastic APM setup instructions in your Kibana.&lt;/p&gt;

&lt;p&gt;Open the file src/otelcollector/otelcol-elastic-config-extras.yml in an editor and replace the following two placeholders:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;YOUR_APM_ENDPOINT_WITHOUT_HTTPS_PREFIX&lt;/strong&gt;: Your Elastic APM endpoint (without https:// prefix) that must also include the port (for example: 987654.xyz.com:443).&lt;br&gt;
&lt;strong&gt;YOUR_APM_SECRET_TOKEN&lt;/strong&gt;: your Elastic APM secret token.&lt;br&gt;
The updated file should look like the below(Make sure to note the actual format for the secret token including the Bearer keyword)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exporters:
  otlp/elastic:
    # !!! Elastic APM https endpoint WITHOUT the "https://" prefix
    endpoint: "11111111111.apm.xyz.xyz.cloud.es.io:443"
    compression: none
    headers:
      Authorization: "Bearer aaaaaaaaaaaaaaa"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;exporters:
  otlp/elastic:
    # !!! Elastic APM https endpoint WITHOUT the "https://" prefix
    endpoint: "11111111111.apm.xyz.xyz.cloud.es.io:443"
    compression: none
    headers:
      Authorization: "Bearer aaaaaaaaaaaaaaa"

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [spanmetrics, otlp/elastic]
    metrics:
      receivers: [otlp, spanmetrics]
      processors: [batch]
      exporters: [otlp/elastic]
    logs:
      receivers: [otlp]
      processors: [batch]
      exporters: [otlp/elastic]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The updated file should look something like the above.&lt;/p&gt;

&lt;p&gt;Optional: If you are using a shared Elastic Cluster, set the environment name so you can distinguish your data. Go to the (project root)/.env file , and locate the _OTEL_RESOURCE_ATTRIBUTES _variable, and add your environment name like below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;OTEL_RESOURCE_ATTRIBUTES="service.namespace=opentelemetry-demo,deployment.environment=&amp;lt;Any Name&amp;gt;"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the demo with the below command from the repository’s root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose up -d
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify that the application is running correctly by checking the links below and testing their functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Web store: http://localhost:8080/
Grafana: http://localhost:8080/grafana/
Load Generator UI: http://localhost:8080/loadgen/
Jaeger UI: http://localhost:8080/jaeger/ui/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To stop the application, run the following from the project root directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kubernetes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a Kubernetes cluster. Set up Kubectl and Helm.&lt;br&gt;
Set up Elastic Observability on Elastic Cloud.&lt;/p&gt;

&lt;p&gt;Create a secret in Kubernetes with the following command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create secret generic elastic-secret \
  --from-literal=elastic_apm_endpoint='YOUR_APM_ENDPOINT_WITHOUT_HTTPS_PREFIX' \
  --from-literal=elastic_apm_secret_token='YOUR_APM_SECRET_TOKEN'

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Execute the following commands to deploy the OpenTelemetry demo to your Kubernetes cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# switch to the kubernetes/elastic-helm directory
cd kubernetes/elastic-helm

# Add the open-telemetry Helm repostiroy
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts

#Update Repo
helm repo update open-telemetry

# deploy the demo through helm install
helm install -f values.yaml my-otel-demo open-telemetry/opentelemetry-demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once your application is up on Kubernetes, validate that all the pods are running in the default namespace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods -n default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify that the application is running correctly by checking the links below and testing their functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Web store: http://localhost:8080/
Grafana: http://localhost:8080/grafana/
Load Generator UI: http://localhost:8080/loadgen/
Jaeger UI: http://localhost:8080/jaeger/ui/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Kubernetes Monitoring:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo includes cluster-level metrics and Kubernetes events collection. To enable Node-level metrics collection and autodiscovery for Redis Pods, run an additional Otel collector Daemonset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm install daemonset open-telemetry/opentelemetry-collector --values daemonset.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explore and analyze the data With Elastic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;View your OTel instrumented services in Kibana's APM Service Map. To access, go to APM in Elastic Observability UI and select servicemap.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj1rlqgrtm7hb6u4g9a6v.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj1rlqgrtm7hb6u4g9a6v.jpeg" alt="Image description" width="568" height="1500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb60mgd673g4gimhsh1y.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvb60mgd673g4gimhsh1y.jpeg" alt="Image description" width="800" height="406"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flypqpteao83qzni4dc3h.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flypqpteao83qzni4dc3h.jpeg" alt="Image description" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you are seeing this, it means that data is being sent to the Elastic cluster by the OpenTelemetry Collector. You can now explore the data and experiment with it.&lt;/p&gt;

&lt;p&gt;To get a comprehensive understanding of all the services and transaction flows between them, you can refer to the APM service map (as demonstrated in the previous step). Additionally, you have the option to examine individual services and the collected transactions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7uj5uzb8k4ms2yqpahld.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7uj5uzb8k4ms2yqpahld.jpeg" alt="Image description" width="800" height="448"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feacf2gz12ujbtf2xcvw2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feacf2gz12ujbtf2xcvw2.jpeg" alt="Image description" width="800" height="223"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the loadgenerator details are listed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Average service latency&lt;/li&gt;
&lt;li&gt;Throughput&lt;/li&gt;
&lt;li&gt;Main transactions&lt;/li&gt;
&lt;li&gt;Failed traction rate&lt;/li&gt;
&lt;li&gt;Errors&lt;/li&gt;
&lt;li&gt;Dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now Click on Transactions → GET(or any request) and we can see the full trace with all the spans. You can further explore and analyze data, examining it with minute detail.&lt;/p&gt;

&lt;p&gt;Elastic utilizes machine learning to identify potential latency issues across services by analyzing the trace. Users can easily access the Latency Correlations tab and run the correlation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgo3ibczj422cssay0hr.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgo3ibczj422cssay0hr.jpeg" alt="Image description" width="800" height="460"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Troubleshoot OTEL data ingest issue:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If you are unable to see any data in your Environment view, start by checking the logs of the OTEL collector with the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose logs -f otelcol
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you come across any errors related to the connection, please double-check the URL and token configuration.&lt;br&gt;
If you are unable to see any services running, try running a full restart of the docker compose and see if that helps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Analyze&lt;/strong&gt;&lt;br&gt;
Analyze your data with Elastic machine learning (ML)&lt;br&gt;
After integrating OpenTelemetry metrics with Elastic, you can begin to analyze your data using Elastic's machine-learning capabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;References:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.linkedin.com/pulse/opentelemetry-elastic-observability-rahul-ranjan-3l6bc/" rel="noopener noreferrer"&gt;https://www.linkedin.com/pulse/opentelemetry-elastic-observability-rahul-ranjan-3l6bc/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/@rahul.fiem/opentelemetry-demo-with-elastic-observability-45d938a65ef8" rel="noopener noreferrer"&gt;https://medium.com/@rahul.fiem/opentelemetry-demo-with-elastic-observability-45d938a65ef8&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://rranjan.hashnode.dev/opentelemetry-with-elastic-observability" rel="noopener noreferrer"&gt;https://rranjan.hashnode.dev/opentelemetry-with-elastic-observability&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Repo: &lt;a href="https://github.com/elastic/opentelemetry-demo" rel="noopener noreferrer"&gt;https://github.com/elastic/opentelemetry-demo &lt;/a&gt;&lt;/p&gt;

</description>
      <category>opentelemetry</category>
      <category>docker</category>
      <category>kubernetes</category>
      <category>elasticsearch</category>
    </item>
    <item>
      <title>Real-Time News Aggregator with Elastic: Leveraging APM, RUM, and Elasticsearch for Optimized Performance</title>
      <dc:creator>Rahul Ranjan</dc:creator>
      <pubDate>Thu, 15 Aug 2024 09:48:57 +0000</pubDate>
      <link>https://dev.to/rranjan/real-time-news-aggregator-with-elastic-leveraging-apm-rum-and-elasticsearch-for-optimized-performance-4fgn</link>
      <guid>https://dev.to/rranjan/real-time-news-aggregator-with-elastic-leveraging-apm-rum-and-elasticsearch-for-optimized-performance-4fgn</guid>
      <description>&lt;p&gt;This guide will explain how to set up a Dockerized news aggregator. This aggregator will retrieve data from an external API, store it in Elasticsearch, and display it using a Flask UI. Additionally, we will integrate our application with Elastic APM for performance monitoring and gather RUM (Real User Monitoring) data from the front-end application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Docker and Docker Compose are installed on your machine.&lt;br&gt;
Elastic Cloud account (or a local Elasticsearch instance).&lt;br&gt;
API Key for the news data source (e.g., NewsAPI).&lt;br&gt;
Basic knowledge of Python and Flask&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Overview&lt;/strong&gt;&lt;br&gt;
This project revolves around a dual-service architecture, powered by Docker containers:&lt;br&gt;
News Aggregation Service:&lt;br&gt;
Flask UI Service:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Real User Monitoring (RUM) Integration&lt;/strong&gt;&lt;br&gt;
To capture real-time data on how users interact with the UI, I integrated Elastic's RUM agent into the index.html file of the Flask service. The RUM agent collects critical data such as page load times, user interactions, and any client-side errors, providing a comprehensive view of the end-user experience.&lt;br&gt;
This integration allows me to optimize the UI continuously, ensuring that any issues affecting the user experience are identified and resolved quickly. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Project Structure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Step-by-Step Guide to Building the Project&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Set Up Elasticsearch on Elastic Cloud&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Sign Up: Begin by signing up for an account on Elastic Cloud.&lt;br&gt;
Create Deployment: Create a new Elasticsearch deployment. This will provide you with a cluster where all news articles will be indexed and stored.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Get Credentials:&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Note down the cloud ID, username, and password for your deployment. These credentials will be needed later to connect your services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Develop the News Aggregation Service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the backend, we implement the logic to fetch news from an external API, process the data, and index it into Elasticsearch. We use a specific library to fetch data and interact with Elasticsearch. Additionally, the backend is instrumented with Elastic APM to capture performance metrics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Develop the Flask UI Service&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The Flask UI is a straightforward web application that retrieves news articles from Elasticsearch and presents them on a web page. We utilize Flask's templating engine to generate the HTML and CSS for the frontend. Additionally, Elastic APM is integrated into the Flask app to monitor frontend performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Integrate Real User Monitoring (RUM)&lt;/strong&gt;&lt;br&gt;
RUM Agent Setup: Added the RUM agent script to the index.html file to capture real-time user interactions. Update the actual value for serviceName, serverUrl and secretToken.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- Elastic APM RUM Agent Configuration --&amp;gt;
    &amp;lt;script&amp;gt;
        function handleScriptError() {
            console.error('Failed to load Elastic APM RUM agent script.');
        }

        function initializeApm() {
            if (window.elasticApm) {
                window.elasticApm.init({
                    serviceName: '',
                    serverUrl: '',
                    secretToken: '',
                    environment: 'news'
                });
                console.log('Elastic APM RUM initialized.');
            } else {
                console.error('Elastic APM RUM agent not loaded.');
            }
        }
    &amp;lt;/script&amp;gt;
    &amp;lt;script src="https://cdn.jsdelivr.net/npm/@elastic/apm-rum@5.9.0/dist/bundles/elastic-apm-rum.umd.min.js"
        onload="initializeApm()" onerror="handleScriptError()"&amp;gt;&amp;lt;/script&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5: Containerize the Services with Docker&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Dockerize the News Aggregation Service: Write a Dockerfile for the news aggregator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use a lightweight Python image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install the required Python packages including Elastic APM
RUN pip install --no-cache-dir -r requirements.txt elastic-apm

# Copy the rest of the application code into the container
COPY . .

# Set environment variables (Update with your actual values)
ENV NEWS_API_KEY=''
ENV ELASTICSEARCH_HOST=''
ENV ELASTICSEARCH_USERNAME=''
ENV ELASTICSEARCH_PASSWORD=''
ENV ELASTIC_APM_SERVER_URL=''
ENV ELASTIC_APM_SECRET_TOKEN=''
ENV ELASTIC_APM_SERVICE_NAME='r'
ENV ELASTIC_APM_ENVIRONMENT='php'
# Run the application
CMD ["python", "stream_news.py"] 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Dockerize the Flask UI Service: Write a Dockerfile for the Flask UI service.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Use the official Python image
FROM python:3.9-slim

# Set the working directory in the container
WORKDIR /app

# Copy the requirements file into the container
COPY requirements.txt .

# Install the required Python packages including Elastic APM
RUN pip install --no-cache-dir -r requirements.txt elastic-apm

# Copy the rest of the application code into the container
COPY . .

# Set environment variables for Elasticsearch (Update with your actual values)
ENV ELASTICSEARCH_HOST=''
ENV ELASTICSEARCH_USERNAME=''
ENV ELASTICSEARCH_PASSWORD=''
ENV ELASTIC_APM_SERVER_URL=''
ENV ELASTIC_APM_SECRET_TOKEN=''
ENV ELASTIC_APM_SERVICE_NAME=''
ENV ELASTIC_APM_ENVIRONMENT=''

# Expose the port Flask runs on
EXPOSE 5001

# Run the Flask application
CMD ["flask", "run", "--host=0.0.0.0", "--port=5001"] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Docker Compose: Create a docker-compose.yml to orchestrate the services.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We define two services in our docker-compose.yml file: news_aggregator and flask_ui. Each service has its own Dockerfile and environment variables, including the Elastic APM configuration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services:
  news_aggregator:
    build:
      context: ./news_aggregator
      dockerfile: Dockerfile.news_aggregator
    container_name: news_aggregator
    environment:
      NEWS_API_KEY: ''
      ELASTICSEARCH_HOST: ''
      ELASTICSEARCH_USERNAME: ''
      ELASTICSEARCH_PASSWORD: ''
      ELASTIC_APM_SERVER_URL: ''
      ELASTIC_APM_SECRET_TOKEN: ''
      ELASTIC_APM_SERVICE_NAME: ''
      ELASTIC_APM_ENVIRONMENT: ''
    restart: always

  flask_ui:
    build:
      context: ./flask_ui
      dockerfile: Dockerfile.ui
    container_name: flask_ui
    ports:
      - "5001:5001"
    environment:
      ELASTICSEARCH_HOST: ''
      ELASTICSEARCH_USERNAME: ''
      ELASTICSEARCH_PASSWORD: ''
      ELASTIC_APM_SERVER_URL: ''
      ELASTIC_APM_SECRET_TOKEN: ''
      ELASTIC_APM_SERVICE_NAME: 'i'
      ELASTIC_APM_ENVIRONMENT: ''
    depends_on:
      - news_aggregator
    restart: always 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6: Deploy and Monitor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Run the Services: Use Docker Compose to start the services.&lt;br&gt;
&lt;code&gt;docker-compose up --build -d&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitor with Kibana&lt;/strong&gt;&lt;br&gt;
Head over to your Elastic Cloud deployment and use Kibana to monitor the performance of your services through the APM and RUM dashboards.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8avuxoqhrid34txllhi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn8avuxoqhrid34txllhi.png" alt="Image description" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1jxg2jtlq6mf9nw49f10.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1jxg2jtlq6mf9nw49f10.png" alt="Image description" width="800" height="283"&gt;&lt;/a&gt;&lt;br&gt;
Real User Monitoring(RUM) Dashboard&lt;/p&gt;

&lt;p&gt;Launch the Flask UI application to stream the news by logging in to &lt;a href="http://127.0.0.1:5001/" rel="noopener noreferrer"&gt;http://127.0.0.1:5001/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm5365h4gx36238ux8hf2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm5365h4gx36238ux8hf2.png" alt="Image description" width="800" height="429"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flask UI Page&lt;/p&gt;

&lt;p&gt;The project code is available at my &lt;a href="https://github.com/rahulranjan22/Real-Time-News-Aggregator-with-Elastic-APM-and-Elasticsearch" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; for download and ready to use by replacing the Elasticsearch, APM credentials.&lt;/p&gt;

&lt;h1&gt;
  
  
  Python #Flask #Elasticsearch #ElasticAPM #Docker #WebDevelopment #RealTimeApplications #Monitoring #DevOps #search
&lt;/h1&gt;

&lt;p&gt;Ref &lt;a href="https://www.linkedin.com/pulse/building-real-time-news-aggregator-elastic-stack-apm-rum-rahul-ranjan-28jpe/" rel="noopener noreferrer"&gt;https://www.linkedin.com/pulse/building-real-time-news-aggregator-elastic-stack-apm-rum-rahul-ranjan-28jpe/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>elasticsearch</category>
      <category>apm</category>
      <category>docker</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
