Skip to content

Commit f261214

Browse files
authored
chore: Update sdk-core (#963)
1 parent 095682c commit f261214

File tree

15 files changed

+280
-139
lines changed

15 files changed

+280
-139
lines changed

packages/core-bridge/Cargo.lock

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core-bridge/index.d.ts

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SpanContext } from '@opentelemetry/api';
2-
import { TLSConfig } from '@temporalio/common/lib/internal-non-workflow';
2+
import type { TLSConfig } from '@temporalio/common/lib/internal-non-workflow';
33

44
export { TLSConfig };
55

@@ -53,32 +53,40 @@ export interface ClientOptions {
5353

5454
/**
5555
* Log directly to console
56+
*
57+
* @experimental
5658
*/
5759
export interface ConsoleLogger {
58-
console: {};
60+
console: {}; // eslint-disable-line @typescript-eslint/ban-types
5961
}
6062

6163
/**
6264
* Forward logs to {@link Runtime} logger
65+
*
66+
* @experimental
6367
*/
6468
export interface ForwardLogger {
6569
forward: {
6670
/**
6771
* What level, if any, logs should be forwarded from core at
6872
*
73+
* @deprecated Use {@link TelemetryOptions.logging.filter} instead
6974
*/
70-
// These strings should match the log::LevelFilter enum in rust
71-
level: LogLevel;
75+
level?: LogLevel;
7276
};
7377
}
7478

7579
/**
7680
* Logger types supported by Core
81+
*
82+
* @experimental
7783
*/
7884
export type Logger = ConsoleLogger | ForwardLogger;
7985

8086
/**
8187
* OpenTelemetry Collector options for exporting metrics or traces
88+
*
89+
* @experimental
8290
*/
8391
export interface OtelCollectorExporter {
8492
otel: {
@@ -95,6 +103,8 @@ export interface OtelCollectorExporter {
95103

96104
/**
97105
* Prometheus metrics exporter options
106+
*
107+
* @experimental
98108
*/
99109
export interface PrometheusMetricsExporter {
100110
prometheus: {
@@ -114,24 +124,29 @@ export interface PrometheusMetricsExporter {
114124
* `temporality` is the type of aggregation temporality for metric export. Applies to both Prometheus and OpenTelemetry exporters.
115125
*
116126
* See the [OpenTelemetry specification](https://github.com/open-telemetry/opentelemetry-specification/blob/ce50e4634efcba8da445cc23523243cb893905cb/specification/metrics/datamodel.md#temporality) for more information.
127+
*
128+
* @experimental
117129
*/
118130
export type MetricsExporter = {
119131
temporality?: 'cumulative' | 'delta';
120132
} & (PrometheusMetricsExporter | OtelCollectorExporter);
121133

122134
/**
123135
* Trace exporters supported by Core
136+
*
137+
* @experimental
124138
*/
125139
export type TraceExporter = OtelCollectorExporter;
126140

141+
/** @experimental */
127142
export interface TelemetryOptions {
128143
/**
129144
* A string in the env filter format specified here:
130145
* https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/struct.EnvFilter.html
131146
*
132-
* Which determines what tracing data is collected in the Core SDK
147+
* Which determines what tracing data is collected in the Core SDK.
133148
*
134-
* @default `temporal_sdk_core=WARN`
149+
* @deprecated Use either `logging.filter` or `tracing.filter` instead
135150
*/
136151
tracingFilter?: string;
137152

@@ -145,17 +160,50 @@ export interface TelemetryOptions {
145160

146161
/**
147162
* Control where to send Rust Core logs
148-
*
149-
* @default log to console
150163
*/
151-
logging?: Logger;
164+
logging?: {
165+
/**
166+
* A string in (env filter format)[https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/struct.EnvFilter.html]
167+
* which determines the verboseness of logging output.
168+
*
169+
* You can use {@link Runtime.makeTelemetryFilterString()} to easily build a correctly formatted filter
170+
* string based on desired log level for Core SDK and other native packages.
171+
*
172+
* **BACKWARD COMPATIBILITY**
173+
*
174+
* If `logging.filter` is missing, the following legacy values (if present) will be used instead (in the given order):
175+
* - {@link ForwardLogger.forward.level} => `makeTelemetryFilterString({ core: level, other: level })`
176+
* - {@link TelemetryOptions.tracingFilter}
177+
* - Default value of `makeTelemetryFilterString({ core: 'INFO', other: 'INFO'})`
178+
*
179+
* @default `makeTelemetryFilterString({ core: 'INFO', other: 'INFO'})` (with some exceptions, as described in backward compatibility note above)
180+
*/
181+
filter?: string;
182+
} & Partial<Logger>;
152183

153184
/**
154185
* Control where to send traces generated by Rust Core, optional and turned off by default.
155186
*
156187
* This is typically used for profiling SDK internals.
157188
*/
158-
tracing?: TraceExporter;
189+
tracing?: {
190+
/**
191+
* A string in (env filter format)[https://docs.rs/tracing-subscriber/0.2.20/tracing_subscriber/struct.EnvFilter.html]
192+
* which determines what tracing data is collected in the Core SDK.
193+
*
194+
* You can use {@link Runtime.makeTelemetryFilterString()} to easily build a correctly formatted filter
195+
* string based on desired log level for Core SDK and other native packages.
196+
*
197+
* **BACKWARD COMPATIBILITY**
198+
*
199+
* If `tracing.filter` is missing, the following legacy values (if present) will be used instead (in the given order):
200+
* - {@link TelemetryOptions.tracingFilter}
201+
* - Default value of `makeTelemetryFilterString({ core: 'INFO', other: 'INFO'})`
202+
*
203+
* @default `makeTelemetryFilterString({ core: 'INFO', other: 'INFO'})` (with some exceptions, as described in backward compatibility note above)
204+
*/
205+
filter?: string;
206+
} & Partial<TraceExporter>;
159207

160208
/**
161209
* Control exporting {@link NativeConnection} and {@link Worker} metrics.
@@ -165,6 +213,21 @@ export interface TelemetryOptions {
165213
metrics?: MetricsExporter;
166214
}
167215

216+
/** @experimental */
217+
export type CompiledTelemetryOptions = {
218+
noTemporalPrefixForMetrics?: boolean;
219+
logging: {
220+
filter: string;
221+
} & (
222+
| { console: {} /* eslint-disable-line @typescript-eslint/ban-types */ }
223+
| { forward: {} /* eslint-disable-line @typescript-eslint/ban-types */ }
224+
);
225+
tracing?: {
226+
filter: string;
227+
} & TraceExporter;
228+
metrics?: MetricsExporter;
229+
};
230+
168231
export interface WorkerOptions {
169232
/**
170233
* A human-readable string that can identify your worker
@@ -367,8 +430,7 @@ export declare type LogsCallback = (err: Error, result: LogEntry[]) => void;
367430

368431
// TODO: improve type, for some reason Error is not accepted here
369432
export declare function registerErrors(errors: Record<string, any>): void;
370-
export declare function initTelemetry(telemOptions: TelemetryOptions): void;
371-
export declare function newRuntime(): Runtime;
433+
export declare function newRuntime(telemOptions: CompiledTelemetryOptions): Runtime;
372434
export declare function newClient(runtime: Runtime, clientOptions: ClientOptions, callback: ClientCallback): void;
373435
export declare function newWorker(client: Client, workerOptions: WorkerOptions, callback: WorkerCallback): void;
374436
export declare function newReplayWorker(

packages/core-bridge/sdk-core

Submodule sdk-core updated 66 files

packages/core-bridge/src/conversions.rs

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::helpers::*;
2-
use log::LevelFilter;
32
use neon::{
43
context::Context,
54
handle::Handle,
@@ -9,13 +8,15 @@ use neon::{
98
use opentelemetry::trace::{SpanContext, SpanId, TraceFlags, TraceId, TraceState};
109
use std::{collections::HashMap, net::SocketAddr, str::FromStr, time::Duration};
1110
use temporal_sdk_core::{
11+
api::telemetry::{
12+
Logger, MetricTemporality, MetricsExporter, OtelCollectorOptions, TelemetryOptions,
13+
TelemetryOptionsBuilder, TraceExportConfig, TraceExporter,
14+
},
1215
api::worker::{WorkerConfig, WorkerConfigBuilder},
1316
ephemeral_server::{
1417
TemporaliteConfig, TemporaliteConfigBuilder, TestServerConfig, TestServerConfigBuilder,
1518
},
16-
ClientOptions, ClientOptionsBuilder, ClientTlsConfig, Logger, MetricTemporality,
17-
MetricsExporter, OtelCollectorOptions, RetryConfig, TelemetryOptions, TelemetryOptionsBuilder,
18-
TlsConfig, TraceExporter, Url,
19+
ClientOptions, ClientOptionsBuilder, ClientTlsConfig, RetryConfig, TlsConfig, Url,
1920
};
2021

2122
pub enum EphemeralServerConfig {
@@ -151,7 +152,7 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
151152
) as u64),
152153
max_elapsed_time: js_optional_value_getter!(
153154
cx,
154-
&retry_config,
155+
retry_config,
155156
"maxElapsedTime",
156157
JsNumber
157158
)
@@ -176,38 +177,27 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
176177

177178
fn as_telemetry_options(&self, cx: &mut FunctionContext) -> NeonResult<TelemetryOptions> {
178179
let mut telemetry_opts = TelemetryOptionsBuilder::default();
179-
180-
if let Some(tf) = js_optional_value_getter!(cx, self, "tracingFilter", JsString) {
181-
telemetry_opts.tracing_filter(tf);
182-
}
183180
telemetry_opts.no_temporal_prefix_for_metrics(
184181
js_optional_value_getter!(cx, self, "noTemporalPrefixForMetrics", JsBoolean)
185182
.unwrap_or_default(),
186183
);
184+
187185
if let Some(ref logging) = js_optional_getter!(cx, self, "logging", JsObject) {
188-
if let Some(_) = get_optional(cx, logging, "console") {
189-
telemetry_opts.logging(Logger::Console);
190-
} else if let Some(ref forward) = js_optional_getter!(cx, logging, "forward", JsObject)
191-
{
192-
let level = js_value_getter!(cx, forward, "level", JsString);
193-
match LevelFilter::from_str(&level) {
194-
Ok(level) => {
195-
telemetry_opts.logging(Logger::Forward(level));
196-
}
197-
Err(err) => cx.throw_type_error(format!(
198-
"Invalid telemetryOptions.logging.forward.level: {}",
199-
err
200-
))?,
201-
}
186+
let filter = js_value_getter!(cx, logging, "filter", JsString);
187+
if get_optional(cx, logging, "console").is_some() {
188+
telemetry_opts.logging(Logger::Console { filter });
189+
} else if get_optional(cx, logging, "forward").is_some() {
190+
telemetry_opts.logging(Logger::Forward { filter });
202191
} else {
203-
cx.throw_type_error(format!(
204-
"Invalid telemetryOptions.logging, missing `console` or `forward` option"
205-
))?
192+
cx.throw_type_error(
193+
"Invalid telemetryOptions.logging, expected either 'console' or 'forward' property",
194+
)?;
206195
}
207196
}
208-
if let Some(metrics) = js_optional_getter!(cx, self, "metrics", JsObject) {
197+
198+
if let Some(ref metrics) = js_optional_getter!(cx, self, "metrics", JsObject) {
209199
if let Some(temporality) =
210-
js_optional_value_getter!(cx, &metrics, "temporality", JsString)
200+
js_optional_value_getter!(cx, metrics, "temporality", JsString)
211201
{
212202
match temporality.as_str() {
213203
"cumulative" => {
@@ -221,56 +211,60 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
221211
}
222212
};
223213
}
224-
225-
if let Some(ref prom) = js_optional_getter!(cx, &metrics, "prometheus", JsObject) {
214+
if let Some(ref prom) = js_optional_getter!(cx, metrics, "prometheus", JsObject) {
226215
let addr = js_value_getter!(cx, prom, "bindAddress", JsString);
227216
match addr.parse::<SocketAddr>() {
228217
Ok(address) => telemetry_opts.metrics(MetricsExporter::Prometheus(address)),
229218
Err(_) => cx.throw_type_error(
230219
"Invalid telemetryOptions.metrics.prometheus.bindAddress",
231220
)?,
232221
};
233-
} else if let Some(ref otel) = js_optional_getter!(cx, &metrics, "otel", JsObject) {
222+
} else if let Some(ref otel) = js_optional_getter!(cx, metrics, "otel", JsObject) {
234223
let url = js_value_getter!(cx, otel, "url", JsString);
235224
let url = match Url::parse(&url) {
236225
Ok(url) => url,
237226
Err(_) => cx.throw_type_error("Invalid telemetryOptions.metrics.otel.url")?,
238227
};
239228
let headers =
240-
if let Some(headers) = js_optional_getter!(cx, otel, "headers", JsObject) {
229+
if let Some(ref headers) = js_optional_getter!(cx, otel, "headers", JsObject) {
241230
headers.as_hash_map_of_string_to_string(cx)?
242231
} else {
243232
Default::default()
244233
};
245234
telemetry_opts
246235
.metrics(MetricsExporter::Otel(OtelCollectorOptions { url, headers }));
247236
} else {
248-
cx.throw_type_error(format!(
249-
"Invalid telemetryOptions.metrics, missing `prometheus` or `otel` option"
250-
))?
237+
cx.throw_type_error(
238+
"Invalid telemetryOptions.metrics, missing `prometheus` or `otel` option",
239+
)?
251240
}
252241
}
253242

254-
if let Some(tracing) = js_optional_getter!(cx, self, "tracing", JsObject) {
255-
if let Some(ref otel) = js_optional_getter!(cx, &tracing, "otel", JsObject) {
243+
if let Some(ref tracing) = js_optional_getter!(cx, self, "tracing", JsObject) {
244+
let filter = js_value_getter!(cx, tracing, "filter", JsString);
245+
if let Some(ref otel) = js_optional_getter!(cx, tracing, "otel", JsObject) {
256246
let url = js_value_getter!(cx, otel, "url", JsString);
257247
let url = match Url::parse(&url) {
258248
Ok(url) => url,
259249
Err(_) => cx.throw_type_error("Invalid telemetryOptions.tracing.otel.url")?,
260250
};
261251
let headers =
262-
if let Some(headers) = js_optional_getter!(cx, otel, "headers", JsObject) {
252+
if let Some(ref headers) = js_optional_getter!(cx, otel, "headers", JsObject) {
263253
headers.as_hash_map_of_string_to_string(cx)?
264254
} else {
265255
Default::default()
266256
};
267-
telemetry_opts.tracing(TraceExporter::Otel(OtelCollectorOptions { url, headers }));
257+
telemetry_opts.tracing(TraceExportConfig {
258+
filter,
259+
exporter: TraceExporter::Otel(OtelCollectorOptions { url, headers }),
260+
});
268261
} else {
269-
cx.throw_type_error(format!(
270-
"Invalid telemetryOptions.tracing, missing `otel` option"
271-
))?
262+
cx.throw_type_error(
263+
"Invalid telemetryOptions.tracing, missing `otel` option",
264+
)?
272265
}
273266
}
267+
274268
telemetry_opts.build().map_err(|reason| {
275269
cx.throw_type_error::<_, TelemetryOptions>(format!("{}", reason))
276270
.unwrap_err()
@@ -363,7 +357,7 @@ impl ObjectHandleConversionsExt for Handle<'_, JsObject> {
363357
let executable = match exec_type.as_str() {
364358
"cached-download" => {
365359
let version = js_optional_value_getter!(cx, &js_executable, "version", JsString)
366-
.unwrap_or("default".to_owned());
360+
.unwrap_or_else(|| "default".to_owned());
367361
let dest_dir =
368362
js_optional_value_getter!(cx, &js_executable, "downloadDir", JsString);
369363

packages/core-bridge/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use testing::*;
1414
fn main(mut cx: ModuleContext) -> NeonResult<()> {
1515
cx.export_function("getTimeOfDay", get_time_of_day)?;
1616
cx.export_function("registerErrors", errors::register_errors)?;
17-
cx.export_function("initTelemetry", init_telemetry)?;
1817
cx.export_function("newRuntime", runtime_new)?;
1918
cx.export_function("newClient", client_new)?;
2019
cx.export_function("clientUpdateHeaders", client_update_headers)?;

0 commit comments

Comments
 (0)