1
1
defmodule PostHog.Config do
2
- @ configuration_schema [
3
- public_url: [
4
- type: :string ,
5
- required: true ,
6
- doc: "`https://us.i.posthog.com` for US cloud or `https://eu.i.posthog.com` for EU cloud"
7
- ] ,
8
- api_key: [
9
- type: :string ,
10
- required: true ,
11
- doc: """
12
- Your PostHog Project API key. Find it in your project's settings under the Project ID section.
13
- """
14
- ] ,
15
- api_client_module: [
16
- type: :atom ,
17
- default: PostHog.API.Client ,
18
- doc: "API client to use"
19
- ] ,
20
- supervisor_name: [
21
- type: :atom ,
22
- default: PostHog ,
23
- doc: "Name of the supervisor process running PostHog"
24
- ] ,
25
- metadata: [
26
- type: { :list , :atom } ,
27
- default: [ ] ,
28
- doc: "List of metadata keys to include in event properties"
29
- ] ,
30
- capture_level: [
31
- type: { :or , [ { :in , Logger . levels ( ) } , nil ] } ,
32
- default: :error ,
33
- doc:
34
- "Minimum level for logs that should be captured as errors. Errors with `crash_reason` are always captured."
35
- ] ,
36
- in_app_otp_apps: [
37
- type: { :list , :atom } ,
38
- default: [ ] ,
39
- doc:
40
- "List of OTP app names of your applications. Stacktrace entries that belong to these apps will be marked as \" in_app\" ."
41
- ]
42
- ]
43
-
44
- @ convenience_schema [
45
- enable: [
46
- type: :boolean ,
47
- default: true ,
48
- doc: "Automatically start PostHog?"
49
- ] ,
50
- enable_error_tracking: [
51
- type: :boolean ,
52
- default: true ,
53
- doc: "Automatically start the logger handler for error tracking?"
54
- ]
55
- ]
56
-
57
2
@ shared_schema [
58
3
test_mode: [
59
4
type: :boolean ,
@@ -62,8 +7,64 @@ defmodule PostHog.Config do
62
7
]
63
8
]
64
9
65
- @ compiled_configuration_schema NimbleOptions . new! ( @ configuration_schema ++ @ shared_schema )
66
- @ compiled_convenience_schema NimbleOptions . new! ( @ convenience_schema ++ @ shared_schema )
10
+ @ configuration_schema [
11
+ public_url: [
12
+ type: :string ,
13
+ required: true ,
14
+ doc:
15
+ "`https://us.i.posthog.com` for US cloud or `https://eu.i.posthog.com` for EU cloud"
16
+ ] ,
17
+ api_key: [
18
+ type: :string ,
19
+ required: true ,
20
+ doc: """
21
+ Your PostHog Project API key. Find it in your project's settings under the Project ID section.
22
+ """
23
+ ] ,
24
+ api_client_module: [
25
+ type: :atom ,
26
+ default: PostHog.API.Client ,
27
+ doc: "API client to use"
28
+ ] ,
29
+ supervisor_name: [
30
+ type: :atom ,
31
+ default: PostHog ,
32
+ doc: "Name of the supervisor process running PostHog"
33
+ ] ,
34
+ metadata: [
35
+ type: { :list , :atom } ,
36
+ default: [ ] ,
37
+ doc: "List of metadata keys to include in event properties"
38
+ ] ,
39
+ capture_level: [
40
+ type: { :or , [ { :in , Logger . levels ( ) } , nil ] } ,
41
+ default: :error ,
42
+ doc:
43
+ "Minimum level for logs that should be captured as errors. Errors with `crash_reason` are always captured."
44
+ ] ,
45
+ in_app_otp_apps: [
46
+ type: { :list , :atom } ,
47
+ default: [ ] ,
48
+ doc:
49
+ "List of OTP app names of your applications. Stacktrace entries that belong to these apps will be marked as \" in_app\" ."
50
+ ]
51
+ ] ++ @ shared_schema
52
+
53
+ @ convenience_schema [
54
+ enable: [
55
+ type: :boolean ,
56
+ default: true ,
57
+ doc: "Automatically start PostHog?"
58
+ ] ,
59
+ enable_error_tracking: [
60
+ type: :boolean ,
61
+ default: true ,
62
+ doc: "Automatically start the logger handler for error tracking?"
63
+ ]
64
+ ] ++ @ shared_schema
65
+
66
+ @ compiled_configuration_schema NimbleOptions . new! ( @ configuration_schema )
67
+ @ compiled_convenience_schema NimbleOptions . new! ( @ convenience_schema )
67
68
68
69
@ moduledoc """
69
70
PostHog configuration
@@ -96,11 +97,11 @@ defmodule PostHog.Config do
96
97
def read! ( ) do
97
98
configuration_options =
98
99
Application . get_all_env ( :posthog )
99
- |> Keyword . take ( Keyword . keys ( @ configuration_schema ++ @ shared_schema ) )
100
+ |> Keyword . take ( Keyword . keys ( @ configuration_schema ) )
100
101
101
102
convenience_options =
102
103
Application . get_all_env ( :posthog )
103
- |> Keyword . take ( Keyword . keys ( @ convenience_schema ++ @ shared_schema ) )
104
+ |> Keyword . take ( Keyword . keys ( @ convenience_schema ) )
104
105
105
106
convenience_options
106
107
|> NimbleOptions . validate! ( @ compiled_convenience_schema )
0 commit comments