SlideShare a Scribd company logo
1 of 64
Download to read offline
May 2019
Distributed Tracing with
Erlang/Elixir projects
Ivan Glushkov 

@gliush
About myself
❖ Postmates, Infra Team
❖ MZ, Infra Team
❖ Echo, Backend Team
❖ MCST, Compiler Project
❖ DevZen podcast, Co-founder
Content
❖ Why Distributed Tracing (DT) is needed
❖ Ideal Design of the DT
❖ OpenTracing + Erlang/Elixir
❖ OpenCensus + Erlang/Elixir
Problem
Problem
Problem
Problem
- debug?
- introspect?
- profile?
Design DT
Design DT: Use Cases
Design DT: Use Cases
❖ Log one request through all the services
Design DT: Use Cases
❖ Log one request through all the services
❖ Gather all operations information (result, time)
Design DT: Use Cases
❖ Log one request through all the services
❖ Gather all operations information (result, time)
❖ Build Dependency Graph
Design DT: Use Cases
❖ Log one request through all the services
❖ Gather all operations information (result, time)
❖ Build Dependency Graph
❖ Analytics (“Daper” paper)
Design DT: Use Cases
❖ Log one request through all the services
❖ Gather all operations information (result, time)
❖ Build Dependency Graph
❖ Analytics (“Daper” paper)
❖ Tags, Logs, Artifacts for each operation
Design DT: Use Cases
❖ Log one request through all the services
❖ Gather all operations information (result, time)
❖ Build Dependency Graph
❖ Analytics (“Daper” paper)
❖ Tags, Logs, Artifacts for each operation
❖ Lines of Business analytics
Design DT: Use Cases
❖ Log one request through all the services
❖ Gather all operations information (result, time)
❖ Build Dependency Graph
❖ Analytics (“Daper” paper)
❖ Tags, Logs, Artifacts for each operation
❖ Lines of Business analytics
❖ QoS, Traffic Control
Design DT: Use Cases
Design DT: Use Cases
Design DT: Idea
❖ User Request ID -> to pass to every subsystem:
Design DT: Idea
❖ User Request ID -> to pass to every subsystem:
❖ HTTP: headers
Design DT: Idea
❖ User Request ID -> to pass to every subsystem:
❖ HTTP: headers
❖ gRPC: additional field / auto wrapping
Design DT: Idea
❖ User Request ID -> to pass to every subsystem:
❖ HTTP: headers
❖ gRPC: additional field / auto wrapping
❖ Event Bus: additional field / auto wrapping
Design DT: Idea
❖ User Request ID -> to pass to every subsystem:
❖ HTTP: headers
❖ gRPC: additional field / auto wrapping
❖ Event Bus: additional field / auto wrapping
❖ Subsystem to have sub-request ID
Design DT: Idea
❖ User Request ID -> to pass to every subsystem:
❖ HTTP: headers
❖ gRPC: additional field / auto wrapping
❖ Event Bus: additional field / auto wrapping
❖ Subsystem to have sub-request ID
❖ Relation to the previous subsystem (parent/child, sequence, …)
❖ Sampling:
❖ pre/intra/post
❖ random/rate limited/by flag
❖ Storage for DT
Design DT: Idea
❖ Lib - Storage?
❖ Lib - Collector - Storage?
❖ Agent - Storage?
❖ Agent - Collector - Storage?
❖ Synchronous?
Design DT: Architecture
❖ Lib - Storage?
❖ Lib - Collector - Storage?
❖ Agent - Storage?
❖ Agent - Collector - Storage?
❖ Synchronous?
Design DT: Architecture
https://github.com/EchoTeam/gtl
Design DT: Architecture
StorageServiceA
ReqID1
ReqID2
ReqID3
ServiceB
ServiceB
Collector
Design DT: Problems
❖ Too many traces -> OOM or CPU is 100%
❖ Too few traces -> miss problems
❖ Decide “on the fly” is difficult
OpenTracing
❖ Cloud Native Computing Foundation (cncf.io) incubating project
❖ Uber, Apple, Pinterest, Couchbase
❖ API specification, libraries
OpenTracing: Concepts
❖ Trace
❖ Span: name, start time, end time
❖ Span: kv tags, kv logs, baggage items
❖ SpanContext
❖ Scopes + Threading + ActiveSpan
❖ Tracers: API + ready solutions
❖ Carriers: API to inject/extract SpanContext
OpenTracing: Flow
1. get SpanContext or start Trace => span.start(SpanContext)
2. span.store(tags/metrics/logs/baggage)
3.
4. span.finish()
OpenTracing: Flow
1. get SpanContext or start Trace => span.start(SpanContext)
2. span.store(tags/metrics/logs/baggage)
3. run another function with SpanContext
4. span.finish()
OpenTracing: Flow
1. get SpanContext or start Trace => span.start(SpanContext)
2. span.store(tags/metrics/logs/baggage)
3. send async message with SpanContext
4. span.finish()
OpenTracing: Flow
1. get SpanContext or start Trace => span.start(SpanContext)
2. span.store(tags/metrics/logs/baggage)
3. HTTP request with SpanContext in headers
4. span.finish()
OpenTracing: Sampling
❖ Sampling ratio
❖ Sampling priority (by tag, flag, …)
OpenTracing: Tracers
❖ CNCF Jaeger (Uber)
❖ LightStep - SaaS solution
❖ Apache SkyWalking
❖ Datadog
❖ Wavefront
OpenTracing: problems
❖ No strict agreement about how to pass the SpanContext
❖ No good libraries for all the languages
OpenTracing: OTTER (Erlang)
❖ Last Update: Apr 2018
❖ Span - record, could be stored:
❖ Process Dict
❖ Multiname Process Dict
❖ Separate Process
OpenTracing: OTTER (Erlang)
Pid = otter_span_id_api:start("my request”),
…
otter_span_id_api:tag(SpanPid, "result", “ok"),
…
otter_span_id_api:finish(SpanPid),
[{

[ %% Condition
{greater, otter_span_duration, 5000000},
{value, otter_span_name, "radius request"}
], [ %% Action
{snapshot_count, [long_radius_request], []},
send_to_zipkin
]
}]
OpenTracing: OTTER (Erlang): Filters
❖ Implement Inject/Extract by yourself
❖ Repeat the semantics for every languages
OpenTracing: OTTER (Erlang): Inject/Extract
❖ Need to write A LOT of code
❖ Flexible configuration
❖ No default agreements
OpenTracing: OTTER (Erlang): Summary
OpenTracing: Ex_Ray (Elixir)
❖ Last update: Oct 2017
❖ Store spans in ETS
❖ Magic with Elixir Macros
defmodule Nested do
use ExRay, pre: :before_fun, post: :after_fun
…
@trace kind: :critical
def fred(a, b), do: blee(a, b)
…
defp before_fun(ctx) do
Span.open(ctx.target, @req_id)
|> :otter.tag(:kind, ctx.meta[:kind])
|> :otter.log(">>> #{ctx.target} with #{ctx.args |> inspect}")
end
end
OpenTracing: Ex_Ray (Elixir)
❖ Less code needed
❖ Low quality code
❖ Memory leaks
❖ Exceptions are not re-raised in wrappers
❖ No default agreements
OpenTracing: Ex_Ray (Elixir): Summary
OpenCensus
❖ Started in Google
❖ Large community (Microsoft, Datadog, Prometheus, …)
❖ Automatic Context Propagation
❖ Reference implementation of the official W3C HTTP tracing header
OpenCensus: Concepts
❖ Trace, Span - similar to OpenTracing
❖ Link between spans: child/parent/unknown
❖ Sampling: Always/Never/Probabilistic (1 in 10000)/RateLimiting (10 per
sec)
❖ Automatic Context Propagation
❖ Stats/Metrics
❖ OpenCensus Service: Agent + Collector
OpenCensus: Concepts
❖ Agent
OpenCensus: Concepts
❖ Collector
OpenCensus: Concepts
OpenCensus Erlang
❖ Public GitHub repo for all Elixir/Erlang libs
❖ Libs for web-servers (Elli, Cowboy, Phoenix, …)
❖ Integrate with minimum effort
OpenCensus Erlang
❖ ETS table for Span data + GC for abandoned Spans
❖ Track SpanContext: process dict / variable
❖ Parse transform or manual context tracking
❖ Logger can receive SpanContext
❖ Metrics
ocp:with_child_span(<<“span1”>>),
ocp:with_child_span(<<“span2”>>, #{}, fun() … end)
OpenCensus Erlang
Process Dictionary Example
handler(Ctx, NextHandler) ->
SpanCtx = oc_trace:with_child_span(Ctx, <<"span-name">>),
try
oc_trace:put_attribute(<<"key">>, <<"value">>, SpanCtx),
{Code, Message} = NextHandler(SpanCtx),
oc_trace:set_status(Code, Message, SpanCtx)
after
oc_trace:finish_span(SpanCtx)
end.
OpenCensus Erlang
Manual Context Handling
❖ Gathers metrics (request processed, bytes sent, latency, …)
❖ Gets parent SpanContext, creates new child Span
❖ Integration (rebar.config change):
[{callback, elli_middleware},
{callback_args, [{mods, [{oc_elli_middleware, []}]
OpenCensus Erlang: Elli
OpenCensus Elixir
❖ Uses opencencus-erlang (e.g. prepare headers with SpanContext)
❖ Implements a macro:

with_child_span “span1” do
…
end
❖ Uses “Phoenix Instrumenter”
❖ Creates Span for any Controller or View
❖ Integration (config.exs):



instrumenters: [OpencensusPhoenix.Instrumenter]
OpenCensus Elixir: Phoenix
❖ Integrates into any pipeline with “Plug”
❖ Gets parent Span from headers
❖ Creates child Span with new attributes (call function to get them)
❖ Integration:
defmodule MyApp.TracePlug do

# some custom configuration

end



plug MyApp.TracePlug
OpenCensus Elixir: Plug
OpenCensus BEAM: Summary
❖ A lot of libraries ready to be used
❖ Seamless integration with other languages
❖ You need to understand the concept
Jaeger
Summary
❖ A lot of advantages: Introspection, Analytics, LoB, QoS
❖ Think about sending metrics with OpenCensus
❖ Easy to integrate even with Erlang/Elixir
Breaking News
❖ Update: May 21st
❖ OpenTracing + OpenCensus 

=> OpenTelemetry
❖ Backward compatibility for both projects
❖ Nov 2019: readonly mode for 

OpenTracing, OpenCensus
Questions
❖ @gliush
❖ Ivan Glushkov
❖ http://devzen.ru

More Related Content

What's hot

Making the big data ecosystem work together with python apache arrow, spark,...
Making the big data ecosystem work together with python  apache arrow, spark,...Making the big data ecosystem work together with python  apache arrow, spark,...
Making the big data ecosystem work together with python apache arrow, spark,...
Holden Karau
 
Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018
Holden Karau
 
Debugging PySpark - PyCon US 2018
Debugging PySpark -  PyCon US 2018Debugging PySpark -  PyCon US 2018
Debugging PySpark - PyCon US 2018
Holden Karau
 
Life of an Fluentd event
Life of an Fluentd eventLife of an Fluentd event
Life of an Fluentd event
Kiyoto Tamura
 

What's hot (20)

Making the big data ecosystem work together with python apache arrow, spark,...
Making the big data ecosystem work together with python  apache arrow, spark,...Making the big data ecosystem work together with python  apache arrow, spark,...
Making the big data ecosystem work together with python apache arrow, spark,...
 
Making the big data ecosystem work together with Python & Apache Arrow, Apach...
Making the big data ecosystem work together with Python & Apache Arrow, Apach...Making the big data ecosystem work together with Python & Apache Arrow, Apach...
Making the big data ecosystem work together with Python & Apache Arrow, Apach...
 
On the need for a W3C community group on RDF Stream Processing
On the need for a W3C community group on RDF Stream ProcessingOn the need for a W3C community group on RDF Stream Processing
On the need for a W3C community group on RDF Stream Processing
 
Ai meetup Neural machine translation updated
Ai meetup Neural machine translation updatedAi meetup Neural machine translation updated
Ai meetup Neural machine translation updated
 
Fluentd - Set Up Once, Collect More
Fluentd - Set Up Once, Collect MoreFluentd - Set Up Once, Collect More
Fluentd - Set Up Once, Collect More
 
AIMeetup #4: Neural-machine-translation
AIMeetup #4: Neural-machine-translationAIMeetup #4: Neural-machine-translation
AIMeetup #4: Neural-machine-translation
 
Accelerating Big Data beyond the JVM - Fosdem 2018
Accelerating Big Data beyond the JVM - Fosdem 2018Accelerating Big Data beyond the JVM - Fosdem 2018
Accelerating Big Data beyond the JVM - Fosdem 2018
 
Google Protocol Buffers
Google Protocol BuffersGoogle Protocol Buffers
Google Protocol Buffers
 
The basics of fluentd
The basics of fluentdThe basics of fluentd
The basics of fluentd
 
Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018
 
Testing and validating distributed systems with Apache Spark and Apache Beam ...
Testing and validating distributed systems with Apache Spark and Apache Beam ...Testing and validating distributed systems with Apache Spark and Apache Beam ...
Testing and validating distributed systems with Apache Spark and Apache Beam ...
 
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
 
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
Building a Pipeline for State-of-the-Art Natural Language Processing Using Hu...
 
Fluentd meetup #2
Fluentd meetup #2Fluentd meetup #2
Fluentd meetup #2
 
How to Write the Fastest JSON Parser/Writer in the World
How to Write the Fastest JSON Parser/Writer in the WorldHow to Write the Fastest JSON Parser/Writer in the World
How to Write the Fastest JSON Parser/Writer in the World
 
#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity#Pharo Days 2016 Reflectivity
#Pharo Days 2016 Reflectivity
 
Debugging PySpark - PyCon US 2018
Debugging PySpark -  PyCon US 2018Debugging PySpark -  PyCon US 2018
Debugging PySpark - PyCon US 2018
 
Life of an Fluentd event
Life of an Fluentd eventLife of an Fluentd event
Life of an Fluentd event
 
The Ring programming language version 1.8 book - Part 45 of 202
The Ring programming language version 1.8 book - Part 45 of 202The Ring programming language version 1.8 book - Part 45 of 202
The Ring programming language version 1.8 book - Part 45 of 202
 
Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!Inside the JVM - Follow the white rabbit!
Inside the JVM - Follow the white rabbit!
 

Similar to Distributed tracing with erlang/elixir

Similar to Distributed tracing with erlang/elixir (20)

Experiences with Microservices at Tuenti
Experiences with Microservices at TuentiExperiences with Microservices at Tuenti
Experiences with Microservices at Tuenti
 
Module: Mutable Content in IPFS
Module: Mutable Content in IPFSModule: Mutable Content in IPFS
Module: Mutable Content in IPFS
 
Engineer Engineering Software
Engineer Engineering SoftwareEngineer Engineering Software
Engineer Engineering Software
 
OSMC 2014: Time to say goodbye to your Nagios setup | Oliver Jan
OSMC 2014: Time to say goodbye to your Nagios setup | Oliver JanOSMC 2014: Time to say goodbye to your Nagios setup | Oliver Jan
OSMC 2014: Time to say goodbye to your Nagios setup | Oliver Jan
 
Time to say goodbye to your Nagios based setup
Time to say goodbye to your Nagios based setupTime to say goodbye to your Nagios based setup
Time to say goodbye to your Nagios based setup
 
Hail hydrate! from stream to lake using open source
Hail hydrate! from stream to lake using open sourceHail hydrate! from stream to lake using open source
Hail hydrate! from stream to lake using open source
 
Centralized + Unified Logging
Centralized + Unified LoggingCentralized + Unified Logging
Centralized + Unified Logging
 
Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015Woo: Writing a fast web server @ ELS2015
Woo: Writing a fast web server @ ELS2015
 
Ngrep commands
Ngrep commandsNgrep commands
Ngrep commands
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
 
Fluentd at HKOScon
Fluentd at HKOSconFluentd at HKOScon
Fluentd at HKOScon
 
Spark streaming
Spark streamingSpark streaming
Spark streaming
 
Kentik Network@Scale (Dan Ellis)
Kentik Network@Scale (Dan Ellis)Kentik Network@Scale (Dan Ellis)
Kentik Network@Scale (Dan Ellis)
 
Open source tools for optimizing your peering infrastructure @ DE-CIX TechMee...
Open source tools for optimizing your peering infrastructure @ DE-CIX TechMee...Open source tools for optimizing your peering infrastructure @ DE-CIX TechMee...
Open source tools for optimizing your peering infrastructure @ DE-CIX TechMee...
 
K. Tzoumas & S. Ewen – Flink Forward Keynote
K. Tzoumas & S. Ewen – Flink Forward KeynoteK. Tzoumas & S. Ewen – Flink Forward Keynote
K. Tzoumas & S. Ewen – Flink Forward Keynote
 
Kubernetes debug like a pro
Kubernetes debug like a proKubernetes debug like a pro
Kubernetes debug like a pro
 
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
Apidays Paris 2023 - Forget TypeScript, Choose Rust to build Robust, Fast and...
 
Self-Service Data Ingestion Using NiFi, StreamSets & Kafka
Self-Service Data Ingestion Using NiFi, StreamSets & KafkaSelf-Service Data Ingestion Using NiFi, StreamSets & Kafka
Self-Service Data Ingestion Using NiFi, StreamSets & Kafka
 
Streams
StreamsStreams
Streams
 
Learning the basics of Apache NiFi for iot OSS Europe 2020
Learning the basics of Apache NiFi for iot OSS Europe 2020Learning the basics of Apache NiFi for iot OSS Europe 2020
Learning the basics of Apache NiFi for iot OSS Europe 2020
 

More from Ivan Glushkov

More from Ivan Glushkov (8)

Kubernetes is not needed to 90 percents of the companies.rus
Kubernetes is not needed to 90 percents of the companies.rusKubernetes is not needed to 90 percents of the companies.rus
Kubernetes is not needed to 90 percents of the companies.rus
 
Mystery Machine Overview
Mystery Machine OverviewMystery Machine Overview
Mystery Machine Overview
 
Raft in details
Raft in detailsRaft in details
Raft in details
 
Hashicorp Nomad
Hashicorp NomadHashicorp Nomad
Hashicorp Nomad
 
Google Dataflow Intro
Google Dataflow IntroGoogle Dataflow Intro
Google Dataflow Intro
 
NewSQL overview, Feb 2015
NewSQL overview, Feb 2015NewSQL overview, Feb 2015
NewSQL overview, Feb 2015
 
Comparing ZooKeeper and Consul
Comparing ZooKeeper and ConsulComparing ZooKeeper and Consul
Comparing ZooKeeper and Consul
 
fp intro
fp introfp intro
fp intro
 

Recently uploaded

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 

Recently uploaded (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Vancouver Psychic Readings, Attraction spells,Br...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
%in Lydenburg+277-882-255-28 abortion pills for sale in Lydenburg
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 

Distributed tracing with erlang/elixir

  • 1. May 2019 Distributed Tracing with Erlang/Elixir projects Ivan Glushkov 
 @gliush
  • 2. About myself ❖ Postmates, Infra Team ❖ MZ, Infra Team ❖ Echo, Backend Team ❖ MCST, Compiler Project ❖ DevZen podcast, Co-founder
  • 3. Content ❖ Why Distributed Tracing (DT) is needed ❖ Ideal Design of the DT ❖ OpenTracing + Erlang/Elixir ❖ OpenCensus + Erlang/Elixir
  • 10. Design DT: Use Cases ❖ Log one request through all the services
  • 11. Design DT: Use Cases ❖ Log one request through all the services ❖ Gather all operations information (result, time)
  • 12. Design DT: Use Cases ❖ Log one request through all the services ❖ Gather all operations information (result, time) ❖ Build Dependency Graph
  • 13. Design DT: Use Cases ❖ Log one request through all the services ❖ Gather all operations information (result, time) ❖ Build Dependency Graph ❖ Analytics (“Daper” paper)
  • 14. Design DT: Use Cases ❖ Log one request through all the services ❖ Gather all operations information (result, time) ❖ Build Dependency Graph ❖ Analytics (“Daper” paper) ❖ Tags, Logs, Artifacts for each operation
  • 15. Design DT: Use Cases ❖ Log one request through all the services ❖ Gather all operations information (result, time) ❖ Build Dependency Graph ❖ Analytics (“Daper” paper) ❖ Tags, Logs, Artifacts for each operation ❖ Lines of Business analytics
  • 16. Design DT: Use Cases ❖ Log one request through all the services ❖ Gather all operations information (result, time) ❖ Build Dependency Graph ❖ Analytics (“Daper” paper) ❖ Tags, Logs, Artifacts for each operation ❖ Lines of Business analytics ❖ QoS, Traffic Control
  • 17. Design DT: Use Cases
  • 18. Design DT: Use Cases
  • 19. Design DT: Idea ❖ User Request ID -> to pass to every subsystem:
  • 20. Design DT: Idea ❖ User Request ID -> to pass to every subsystem: ❖ HTTP: headers
  • 21. Design DT: Idea ❖ User Request ID -> to pass to every subsystem: ❖ HTTP: headers ❖ gRPC: additional field / auto wrapping
  • 22. Design DT: Idea ❖ User Request ID -> to pass to every subsystem: ❖ HTTP: headers ❖ gRPC: additional field / auto wrapping ❖ Event Bus: additional field / auto wrapping
  • 23. Design DT: Idea ❖ User Request ID -> to pass to every subsystem: ❖ HTTP: headers ❖ gRPC: additional field / auto wrapping ❖ Event Bus: additional field / auto wrapping ❖ Subsystem to have sub-request ID
  • 24. Design DT: Idea ❖ User Request ID -> to pass to every subsystem: ❖ HTTP: headers ❖ gRPC: additional field / auto wrapping ❖ Event Bus: additional field / auto wrapping ❖ Subsystem to have sub-request ID ❖ Relation to the previous subsystem (parent/child, sequence, …)
  • 25. ❖ Sampling: ❖ pre/intra/post ❖ random/rate limited/by flag ❖ Storage for DT Design DT: Idea
  • 26. ❖ Lib - Storage? ❖ Lib - Collector - Storage? ❖ Agent - Storage? ❖ Agent - Collector - Storage? ❖ Synchronous? Design DT: Architecture
  • 27. ❖ Lib - Storage? ❖ Lib - Collector - Storage? ❖ Agent - Storage? ❖ Agent - Collector - Storage? ❖ Synchronous? Design DT: Architecture https://github.com/EchoTeam/gtl
  • 29. Design DT: Problems ❖ Too many traces -> OOM or CPU is 100% ❖ Too few traces -> miss problems ❖ Decide “on the fly” is difficult
  • 30. OpenTracing ❖ Cloud Native Computing Foundation (cncf.io) incubating project ❖ Uber, Apple, Pinterest, Couchbase ❖ API specification, libraries
  • 31. OpenTracing: Concepts ❖ Trace ❖ Span: name, start time, end time ❖ Span: kv tags, kv logs, baggage items ❖ SpanContext ❖ Scopes + Threading + ActiveSpan ❖ Tracers: API + ready solutions ❖ Carriers: API to inject/extract SpanContext
  • 32. OpenTracing: Flow 1. get SpanContext or start Trace => span.start(SpanContext) 2. span.store(tags/metrics/logs/baggage) 3. 4. span.finish()
  • 33. OpenTracing: Flow 1. get SpanContext or start Trace => span.start(SpanContext) 2. span.store(tags/metrics/logs/baggage) 3. run another function with SpanContext 4. span.finish()
  • 34. OpenTracing: Flow 1. get SpanContext or start Trace => span.start(SpanContext) 2. span.store(tags/metrics/logs/baggage) 3. send async message with SpanContext 4. span.finish()
  • 35. OpenTracing: Flow 1. get SpanContext or start Trace => span.start(SpanContext) 2. span.store(tags/metrics/logs/baggage) 3. HTTP request with SpanContext in headers 4. span.finish()
  • 36. OpenTracing: Sampling ❖ Sampling ratio ❖ Sampling priority (by tag, flag, …)
  • 37. OpenTracing: Tracers ❖ CNCF Jaeger (Uber) ❖ LightStep - SaaS solution ❖ Apache SkyWalking ❖ Datadog ❖ Wavefront
  • 38. OpenTracing: problems ❖ No strict agreement about how to pass the SpanContext ❖ No good libraries for all the languages
  • 39. OpenTracing: OTTER (Erlang) ❖ Last Update: Apr 2018
  • 40. ❖ Span - record, could be stored: ❖ Process Dict ❖ Multiname Process Dict ❖ Separate Process OpenTracing: OTTER (Erlang) Pid = otter_span_id_api:start("my request”), … otter_span_id_api:tag(SpanPid, "result", “ok"), … otter_span_id_api:finish(SpanPid),
  • 41. [{
 [ %% Condition {greater, otter_span_duration, 5000000}, {value, otter_span_name, "radius request"} ], [ %% Action {snapshot_count, [long_radius_request], []}, send_to_zipkin ] }] OpenTracing: OTTER (Erlang): Filters
  • 42. ❖ Implement Inject/Extract by yourself ❖ Repeat the semantics for every languages OpenTracing: OTTER (Erlang): Inject/Extract
  • 43. ❖ Need to write A LOT of code ❖ Flexible configuration ❖ No default agreements OpenTracing: OTTER (Erlang): Summary
  • 44. OpenTracing: Ex_Ray (Elixir) ❖ Last update: Oct 2017 ❖ Store spans in ETS ❖ Magic with Elixir Macros
  • 45. defmodule Nested do use ExRay, pre: :before_fun, post: :after_fun … @trace kind: :critical def fred(a, b), do: blee(a, b) … defp before_fun(ctx) do Span.open(ctx.target, @req_id) |> :otter.tag(:kind, ctx.meta[:kind]) |> :otter.log(">>> #{ctx.target} with #{ctx.args |> inspect}") end end OpenTracing: Ex_Ray (Elixir)
  • 46. ❖ Less code needed ❖ Low quality code ❖ Memory leaks ❖ Exceptions are not re-raised in wrappers ❖ No default agreements OpenTracing: Ex_Ray (Elixir): Summary
  • 47. OpenCensus ❖ Started in Google ❖ Large community (Microsoft, Datadog, Prometheus, …) ❖ Automatic Context Propagation ❖ Reference implementation of the official W3C HTTP tracing header
  • 48. OpenCensus: Concepts ❖ Trace, Span - similar to OpenTracing ❖ Link between spans: child/parent/unknown ❖ Sampling: Always/Never/Probabilistic (1 in 10000)/RateLimiting (10 per sec) ❖ Automatic Context Propagation ❖ Stats/Metrics
  • 49. ❖ OpenCensus Service: Agent + Collector OpenCensus: Concepts
  • 52. OpenCensus Erlang ❖ Public GitHub repo for all Elixir/Erlang libs ❖ Libs for web-servers (Elli, Cowboy, Phoenix, …) ❖ Integrate with minimum effort
  • 53. OpenCensus Erlang ❖ ETS table for Span data + GC for abandoned Spans ❖ Track SpanContext: process dict / variable ❖ Parse transform or manual context tracking ❖ Logger can receive SpanContext ❖ Metrics
  • 54. ocp:with_child_span(<<“span1”>>), ocp:with_child_span(<<“span2”>>, #{}, fun() … end) OpenCensus Erlang Process Dictionary Example
  • 55. handler(Ctx, NextHandler) -> SpanCtx = oc_trace:with_child_span(Ctx, <<"span-name">>), try oc_trace:put_attribute(<<"key">>, <<"value">>, SpanCtx), {Code, Message} = NextHandler(SpanCtx), oc_trace:set_status(Code, Message, SpanCtx) after oc_trace:finish_span(SpanCtx) end. OpenCensus Erlang Manual Context Handling
  • 56. ❖ Gathers metrics (request processed, bytes sent, latency, …) ❖ Gets parent SpanContext, creates new child Span ❖ Integration (rebar.config change): [{callback, elli_middleware}, {callback_args, [{mods, [{oc_elli_middleware, []}] OpenCensus Erlang: Elli
  • 57. OpenCensus Elixir ❖ Uses opencencus-erlang (e.g. prepare headers with SpanContext) ❖ Implements a macro:
 with_child_span “span1” do … end
  • 58. ❖ Uses “Phoenix Instrumenter” ❖ Creates Span for any Controller or View ❖ Integration (config.exs):
 
 instrumenters: [OpencensusPhoenix.Instrumenter] OpenCensus Elixir: Phoenix
  • 59. ❖ Integrates into any pipeline with “Plug” ❖ Gets parent Span from headers ❖ Creates child Span with new attributes (call function to get them) ❖ Integration: defmodule MyApp.TracePlug do
 # some custom configuration
 end
 
 plug MyApp.TracePlug OpenCensus Elixir: Plug
  • 60. OpenCensus BEAM: Summary ❖ A lot of libraries ready to be used ❖ Seamless integration with other languages ❖ You need to understand the concept
  • 62. Summary ❖ A lot of advantages: Introspection, Analytics, LoB, QoS ❖ Think about sending metrics with OpenCensus ❖ Easy to integrate even with Erlang/Elixir
  • 63. Breaking News ❖ Update: May 21st ❖ OpenTracing + OpenCensus 
 => OpenTelemetry ❖ Backward compatibility for both projects ❖ Nov 2019: readonly mode for 
 OpenTracing, OpenCensus
  • 64. Questions ❖ @gliush ❖ Ivan Glushkov ❖ http://devzen.ru