-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathstarter.rb
More file actions
39 lines (34 loc) · 1.7 KB
/
starter.rb
File metadata and controls
39 lines (34 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
require 'opentelemetry/sdk'
require 'temporalio/client'
require 'temporalio/contrib/open_telemetry'
require 'temporalio/env_config'
require 'temporalio/runtime'
require_relative 'greeting_workflow'
require_relative 'util'
# Configure metrics and tracing
OpenTelemetry::Util.configure_metrics_and_tracing
# Demonstrate that we can create a custom metric right on the runtime, though most users won't need this
Temporalio::Runtime.default.metric_meter.create_metric(:gauge, 'my-starter-gauge', value_type: :float)
.with_additional_attributes({ 'my-group-attr' => 'simple-starters' })
.record(1.23)
# Create a client with the tracing interceptor set using the tracer
tracer = OpenTelemetry.tracer_provider.tracer('temporal_ruby_sample', '0.1.0')
args, kwargs = Temporalio::EnvConfig::ClientConfig.load_client_connect_options
args[0] ||= 'localhost:7233' # Default address
args[1] ||= 'default' # Default namespace
interceptors = [Temporalio::Contrib::OpenTelemetry::TracingInterceptor.new(tracer)]
client = Temporalio::Client.connect(*args, **kwargs, interceptors:)
# Demonstrate an arbitrary outer span. Most users may not explicitly create outer spans before using clients and rather
# solely rely on the implicit ones created in the client via interceptor, but this demonstrates that it can be done.
tracer.in_span('my-client-span', attributes: { 'my-group-attr' => 'simple-client' }) do
# Run workflow
puts 'Executing workflow'
result = client.execute_workflow(
OpenTelemetry::GreetingWorkflow,
'User', # Workflow argument
id: 'opentelemetry-sample-workflow-id',
task_queue: 'opentelemetry-sample'
)
puts "Workflow result: #{result}"
end