Class: PlatformSdk::Observability::Langfuse::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/platform_sdk/observability/langfuse/configuration.rb

Constant Summary collapse

DEFAULT_BASE_URL =

US region; set LANGFUSE_BASE_URL for eu.cloud.langfuse.com, jp.cloud.langfuse.com, etc.

'https://us.cloud.langfuse.com'
DEFAULT_PROMPT_LABEL =
'latest'
DEFAULT_BATCH_INTERVAL_MS =
5_000
OTLP_TRACES_PATH =
'/api/public/otel/v1/traces'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name:, environment: nil, prompt_label: nil, exporter: nil) ⇒ Configuration

Returns a new instance of Configuration.



19
20
21
22
23
24
25
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 19

def initialize(app_name:, environment: nil, prompt_label: nil, exporter: nil)
  @app_name = coerce_string(app_name)
  @environment = coerce_string(environment || ENV.fetch('RAILS_ENV', 'development'))
  @prompt_label = coerce_string(prompt_label || ENV.fetch('LANGFUSE_PROMPT_LABEL', DEFAULT_PROMPT_LABEL))
  @exporter = exporter
  @enabled = compute_enabled
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



17
18
19
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 17

def app_name
  @app_name
end

#environmentObject (readonly)

Returns the value of attribute environment.



17
18
19
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 17

def environment
  @environment
end

#exporterObject (readonly)

Returns the value of attribute exporter.



17
18
19
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 17

def exporter
  @exporter
end

#prompt_labelObject (readonly)

Returns the value of attribute prompt_label.



17
18
19
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 17

def prompt_label
  @prompt_label
end

Instance Method Details

#default_resource_attributesObject



35
36
37
38
39
40
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 35

def default_resource_attributes
  {
    'service.name' => app_name,
    'deployment.environment' => environment
  }
end

#enabled?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 27

def enabled?
  @enabled
end

#force_flush_and_shutdownObject



50
51
52
53
54
55
56
57
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 50

def force_flush_and_shutdown
  return if @shut_down
  return unless @tracer_provider

  @tracer_provider.force_flush(timeout: 5)
  @tracer_provider.shutdown(timeout: 5)
  @shut_down = true
end

#otlp_endpointObject



31
32
33
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 31

def otlp_endpoint
  "#{base_url}#{OTLP_TRACES_PATH}"
end

#tracerObject



42
43
44
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 42

def tracer
  @tracer ||= tracer_provider.tracer('platform_sdk.observability.langfuse', PlatformSdk::VERSION)
end

#tracer_providerObject



46
47
48
# File 'lib/platform_sdk/observability/langfuse/configuration.rb', line 46

def tracer_provider
  @tracer_provider ||= build_tracer_provider
end