{"id":3989,"date":"2024-06-19T16:49:16","date_gmt":"2024-06-19T16:49:16","guid":{"rendered":"https:\/\/wiki.thomasandsofia.com\/?p=3989"},"modified":"2024-06-28T20:22:50","modified_gmt":"2024-06-28T20:22:50","slug":"observability-and-opentelemetry-ch2-installing-the-sdk-6-13","status":"publish","type":"post","link":"https:\/\/wiki.thomasandsofia.com\/?p=3989","title":{"rendered":"Observability and OpenTelemetry &#8211; CH2 &#8211; Installing the SDK 6 &#8211; 13"},"content":{"rendered":"<h1>6. Clone the demo app<\/h1>\n<div class=\"article-asset--container--IvjZK\">\n<div class=\"article-asset--content--H92b2 rt-scaffolding\" data-purpose=\"safely-set-inner-html:rich-text-viewer:html\">\n<ul>\n<li>Go to: <a href=\"https:\/\/github.com\/habmic\/opentelemetry-101\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/habmic\/opentelemetry-101<\/a><\/li>\n<li>Clone the repo &#8211; giving a star never hurt \ud83d\ude09<\/li>\n<li>cd to opentelemetry-101<\/li>\n<li>run &#8216;git checkout 1&#8217; &#8211; we use tags to jump to different stages of the project<\/li>\n<li>docker-compose up<\/li>\n<\/ul>\n<h1>8. Install OpenTelemetry<\/h1>\n<p><a href=\"https:\/\/github.com\/habmic\/opentelemetry-101\/blob\/main\/docs\/installing-opentelemetry.md\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/habmic\/opentelemetry-101\/blob\/main\/docs\/installing-opentelemetry.md<\/a><\/p>\n<h3>Installing the libraries<\/h3>\n<pre>yarn add @opentelemetry\/api @opentelemetry\/auto-instrumentations-node @opentelemetry\/exporter-trace-otlp-proto @opentelemetry\/sdk-node<\/pre>\n<h3>Verify everything is working<\/h3>\n<p><strong>todo service<\/strong><\/p>\n<p><a href=\"http:\/\/localhost:8081\/todos\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:8081\/todos<\/a><\/p>\n<p><strong>Jaeger<\/strong><\/p>\n<p><a href=\"http:\/\/localhost:16686\/search\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:16686\/search<\/a><\/p>\n<\/div>\n<\/div>\n<h1>9. How Distributed traces are made<\/h1>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3995\" src=\"https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1.png\" alt=\"\" width=\"1460\" height=\"738\" srcset=\"https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1.png 1460w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1-300x152.png 300w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1-1024x518.png 1024w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1-768x388.png 768w, https:\/\/wiki.thomasandsofia.com\/wp-content\/uploads\/2024\/06\/otel9-1-150x76.png 150w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/p>\n<p>OpenTelemetry (OTEL) context is sent in HTTP headers<\/p>\n<ul>\n<li>Span ID<\/li>\n<li>Parent Span ID\n<ul>\n<li>If not defined, then the root id is used<\/li>\n<\/ul>\n<\/li>\n<li>Trace ID<\/li>\n<\/ul>\n<h1>10. Adding Metrics<\/h1>\n<p><strong>Follow steps in the link below:<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/habmic\/opentelemetry-101\/blob\/main\/docs\/adding-metrics.md\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/habmic\/opentelemetry-101\/blob\/main\/docs\/adding-metrics.md<\/a><\/p>\n<p><span style=\"color: #ff0000;\"><em>Notes: <\/em><\/span><\/p>\n<p><span style=\"color: #ff0000;\"><em>&#8211; Add the &#8216;Running Prometheus&#8217; code to the docker-compose.yml file and not prometheus.yml as hinted by the online doc!<\/em><\/span><\/p>\n<p><em><span style=\"color: #ff0000;\">&#8211; sleep command does not exist. Add the following line before app.get (all one line)<\/span><\/em><\/p>\n<pre>const sleep = (time: number) =&gt; { return new Promise((resolve) =&gt; { setTimeout(resolve, time) }) };<\/pre>\n<p><em><span style=\"color: #ff0000;\">&#8211; fail fails! Something about cannot send headers after &#8230; (<\/span><\/em><\/p>\n<pre>if (req.query['fail']){\r\n    console.error('Really bad error!');\r\n    res.sendStatus(500);\r\n    return;\r\n}\r\n\r\n<\/pre>\n<h3>Prometheus<\/h3>\n<ul>\n<li>Prometheus is an open-source time-series database\n<ul>\n<li>Also provided by the CNCF Cloud Native Computing Foundation<\/li>\n<\/ul>\n<\/li>\n<li>Prometheus &#8216;scrapes&#8217; for metrics.\n<ul>\n<li>The targets are noted in the prometheus.yml file, hitting the source files on their assigned ports.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Verify<\/h2>\n<ul>\n<li>API Calls\n<ul>\n<li><a href=\"http:\/\/localhost:8081\/todos?slow=1\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:8081\/todos?slow=1<\/a><\/li>\n<li><a href=\"http:\/\/localhost:8081\/todos?fail=1\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost:8081\/todos?fail=1<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"http:\/\/localhost:16686\/search\" target=\"_blank\" rel=\"noopener\">Jaeger<\/a><\/li>\n<li><a href=\"http:\/\/localhost:9090\" target=\"_blank\" rel=\"noopener\">Prometheus<\/a>\n<ul>\n<li><code>histogram_quantile(0.95, sum(rate(http_calls_bucket[1m])) by (le, route))<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h1>11. Correlating logs with traces<\/h1>\n<h1>12. Creating manual spans<\/h1>\n<h1>13. Creating span attributes (tags)<\/h1>\n<ul>\n<li>Key: Value pairs<\/li>\n<li>Can be used to search in Jaeger<\/li>\n<li>Custom tags can be added\n<ul>\n<li>i.e. User ID<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>opentelemetry.trace.getActiveSpan()?.setAttribute('userId',123);\r\nopentelemetry.trace.getActiveSpan()?.setAttributes({'userId',123});<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>6. Clone the demo app Go to: https:\/\/github.com\/habmic\/opentelemetry-101 Clone the repo &#8211; giving a star never hurt \ud83d\ude09 cd to opentelemetry-101 run &#8216;git checkout 1&#8217; &#8211; we use tags to jump to different stages of the project docker-compose up 8. Install OpenTelemetry https:\/\/github.com\/habmic\/opentelemetry-101\/blob\/main\/docs\/installing-opentelemetry.md Installing the libraries yarn add @opentelemetry\/api @opentelemetry\/auto-instrumentations-node @opentelemetry\/exporter-trace-otlp-proto @opentelemetry\/sdk-node Verify everything is ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/wiki.thomasandsofia.com\/?p=3989\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3989","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/3989","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3989"}],"version-history":[{"count":8,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/3989\/revisions"}],"predecessor-version":[{"id":4001,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=\/wp\/v2\/posts\/3989\/revisions\/4001"}],"wp:attachment":[{"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wiki.thomasandsofia.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}