1414import { NodeSDK } from "@opentelemetry/sdk-node" ;
1515import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http" ;
1616import { SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base" ;
17- import { Resource } from "@opentelemetry/resources" ;
17+ import { resourceFromAttributes } from "@opentelemetry/resources" ;
1818import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions" ;
1919
2020// Load environment variables from .env file
@@ -30,7 +30,7 @@ const traceExporter = new OTLPTraceExporter({
3030} ) ;
3131
3232const sdk = new NodeSDK ( {
33- resource : new Resource ( {
33+ resource : resourceFromAttributes ( {
3434 [ ATTR_SERVICE_NAME ] : "durabletask-js-tracing-example" ,
3535 } ) ,
3636 spanProcessors : [ new SimpleSpanProcessor ( traceExporter ) ] ,
@@ -43,8 +43,8 @@ console.log(`OpenTelemetry SDK started – exporting traces to ${otlpEndpoint}`)
4343// 2. Durable Task imports (after OTel is initialised)
4444// --------------------------------------------------------------------------
4545import {
46- createAzureManagedClient ,
47- createAzureManagedWorkerBuilder ,
46+ DurableTaskAzureManagedClientBuilder ,
47+ DurableTaskAzureManagedWorkerBuilder ,
4848 createAzureLogger ,
4949} from "@microsoft/durabletask-js-azuremanaged" ;
5050import { ActivityContext } from "@microsoft/durabletask-js/dist/task/context/activity-context" ;
@@ -56,19 +56,22 @@ import { whenAll } from "@microsoft/durabletask-js/dist/task";
5656// 3. Application code
5757// --------------------------------------------------------------------------
5858( async ( ) => {
59- const logger = createAzureLogger ( "tracing-example" ) ;
59+ // Use the Azure logger adapter for the SDK internals – it respects AZURE_LOG_LEVEL
60+ // and suppresses debug/verbose messages by default, keeping the console output clean.
61+ // Set AZURE_LOG_LEVEL=verbose to see internal SDK logs.
62+ const sdkLogger = createAzureLogger ( ) ;
6063
6164 // --- Configuration ---
6265 const connectionString = process . env . DURABLE_TASK_SCHEDULER_CONNECTION_STRING ;
6366 const endpoint = process . env . AZURE_DTS_ENDPOINT ;
6467 const taskHubName = process . env . AZURE_DTS_TASKHUB ;
6568
6669 if ( ! connectionString && ( ! endpoint || ! taskHubName ) ) {
67- logger . error (
70+ console . error (
6871 "Error: Either DURABLE_TASK_SCHEDULER_CONNECTION_STRING or both AZURE_DTS_ENDPOINT and AZURE_DTS_TASKHUB must be set." ,
6972 ) ;
70- logger . info ( "\nFor the DTS emulator, set:" ) ;
71- logger . info (
73+ console . log ( "\nFor the DTS emulator, set:" ) ;
74+ console . log (
7275 ' DURABLE_TASK_SCHEDULER_CONNECTION_STRING="Endpoint=http://localhost:8080;Authentication=None;TaskHub=default"' ,
7376 ) ;
7477 process . exit ( 1 ) ;
@@ -78,22 +81,22 @@ import { whenAll } from "@microsoft/durabletask-js/dist/task";
7881
7982 /** Simulates fetching data from an external service. */
8083 const fetchData = async ( _ctx : ActivityContext , source : string ) : Promise < string > => {
81- logger . info ( ` [fetchData] Fetching data from "${ source } "...`) ;
84+ console . log ( ` [fetchData] Fetching data from "${ source } "...`) ;
8285 // Simulate network latency
8386 await new Promise ( ( r ) => setTimeout ( r , 300 + Math . random ( ) * 200 ) ) ;
8487 return `data-from-${ source } ` ;
8588 } ;
8689
8790 /** Simulates transforming a piece of data. */
8891 const transformData = async ( _ctx : ActivityContext , input : string ) : Promise < string > => {
89- logger . info ( ` [transformData] Transforming "${ input } "...`) ;
92+ console . log ( ` [transformData] Transforming "${ input } "...`) ;
9093 await new Promise ( ( r ) => setTimeout ( r , 200 ) ) ;
9194 return `transformed(${ input } )` ;
9295 } ;
9396
9497 /** Simulates persisting results to a database. */
9598 const saveResults = async ( _ctx : ActivityContext , results : string [ ] ) : Promise < number > => {
96- logger . info ( ` [saveResults] Saving ${ results . length } results...`) ;
99+ console . log ( ` [saveResults] Saving ${ results . length } results...`) ;
97100 await new Promise ( ( r ) => setTimeout ( r , 150 ) ) ;
98101 return results . length ;
99102 } ;
@@ -163,7 +166,7 @@ import { whenAll } from "@microsoft/durabletask-js/dist/task";
163166 } ;
164167
165168 const greetCity = async ( _ctx : ActivityContext , city : string ) : Promise < string > => {
166- logger . info ( ` [greetCity] Greeting ${ city } `) ;
169+ console . log ( ` [greetCity] Greeting ${ city } `) ;
167170 await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
168171 return `Hello, ${ city } !` ;
169172 } ;
@@ -174,69 +177,66 @@ import { whenAll } from "@microsoft/durabletask-js/dist/task";
174177 let worker ;
175178
176179 try {
180+ const clientBuilder = new DurableTaskAzureManagedClientBuilder ( ) . logger ( sdkLogger ) ;
181+ const workerBuilder = new DurableTaskAzureManagedWorkerBuilder ( ) . logger ( sdkLogger ) ;
182+
177183 if ( connectionString ) {
178- logger . info ( "Using connection string..." ) ;
179- client = createAzureManagedClient ( connectionString ) ;
180- worker = createAzureManagedWorkerBuilder ( connectionString )
181- . addOrchestrator ( dataPipelineOrchestrator )
182- . addOrchestrator ( sequenceOrchestrator )
183- . addActivity ( fetchData )
184- . addActivity ( transformData )
185- . addActivity ( saveResults )
186- . addActivity ( getDataSources )
187- . addActivity ( greetCity )
188- . build ( ) ;
184+ clientBuilder . connectionString ( connectionString ) ;
185+ workerBuilder . connectionString ( connectionString ) ;
189186 } else {
190187 const { DefaultAzureCredential } = await import ( "@azure/identity" ) ;
191188 const credential = new DefaultAzureCredential ( ) ;
192- client = createAzureManagedClient ( endpoint ! , taskHubName ! , credential ) ;
193- worker = createAzureManagedWorkerBuilder ( endpoint ! , taskHubName ! , credential )
194- . addOrchestrator ( dataPipelineOrchestrator )
195- . addOrchestrator ( sequenceOrchestrator )
196- . addActivity ( fetchData )
197- . addActivity ( transformData )
198- . addActivity ( saveResults )
199- . addActivity ( getDataSources )
200- . addActivity ( greetCity )
201- . build ( ) ;
189+ clientBuilder . endpoint ( endpoint ! , taskHubName ! , credential ) ;
190+ workerBuilder . endpoint ( endpoint ! , taskHubName ! , credential ) ;
202191 }
203192
193+ client = clientBuilder . build ( ) ;
194+ worker = workerBuilder
195+ . addOrchestrator ( dataPipelineOrchestrator )
196+ . addOrchestrator ( sequenceOrchestrator )
197+ . addActivity ( fetchData )
198+ . addActivity ( transformData )
199+ . addActivity ( saveResults )
200+ . addActivity ( getDataSources )
201+ . addActivity ( greetCity )
202+ . build ( ) ;
203+
204204 // --- Start worker ---
205- logger . info ( "Starting worker..." ) ;
205+ console . log ( "Starting worker..." ) ;
206206 await worker . start ( ) ;
207- logger . info ( "Worker started." ) ;
207+ console . log ( "Worker started." ) ;
208208
209209 // --- Run orchestrations ---
210210
211211 // 1) Sequence orchestration
212- logger . info ( "\n=== Sequence Orchestration ===" ) ;
212+ console . log ( "\n=== Sequence Orchestration ===" ) ;
213213 const seqId = await client . scheduleNewOrchestration ( sequenceOrchestrator ) ;
214- logger . info ( `Scheduled: ${ seqId } ` ) ;
214+ console . log ( `Scheduled: ${ seqId } ` ) ;
215215 const seqState = await client . waitForOrchestrationCompletion ( seqId , undefined , 60 ) ;
216- logger . info ( `Completed – result: ${ seqState ?. serializedOutput } ` ) ;
216+ console . log ( `Completed – result: ${ seqState ?. serializedOutput } ` ) ;
217217
218218 // 2) Data pipeline orchestration (fan-out/fan-in)
219- logger . info ( "\n=== Data Pipeline Orchestration ===" ) ;
219+ console . log ( "\n=== Data Pipeline Orchestration ===" ) ;
220220 const pipelineId = await client . scheduleNewOrchestration ( dataPipelineOrchestrator ) ;
221- logger . info ( `Scheduled: ${ pipelineId } ` ) ;
221+ console . log ( `Scheduled: ${ pipelineId } ` ) ;
222222 const pipelineState = await client . waitForOrchestrationCompletion ( pipelineId , undefined , 60 ) ;
223- logger . info ( `Completed – result: ${ pipelineState ?. serializedOutput } ` ) ;
223+ console . log ( `Completed – result: ${ pipelineState ?. serializedOutput } ` ) ;
224224
225- logger . info ( "\n=== All orchestrations completed! ===" ) ;
226- logger . info (
225+ console . log ( "\n=== All orchestrations completed! ===" ) ;
226+ console . log (
227227 `Open Jaeger UI at http://localhost:16686 and search for service "durabletask-js-tracing-example" to view traces.` ,
228228 ) ;
229229 } catch ( error ) {
230- logger . error ( "Error:" , error ) ;
230+ console . error ( "Error:" , error ) ;
231231 process . exit ( 1 ) ;
232232 } finally {
233- logger . info ( "\nShutting down..." ) ;
233+ console . log ( "\nShutting down..." ) ;
234234 if ( worker ) await worker . stop ( ) ;
235235 if ( client ) await client . stop ( ) ;
236236
237237 // Flush remaining spans before exit
238238 await sdk . shutdown ( ) ;
239- logger . info ( "Done." ) ;
239+ console . log ( "Done." ) ;
240240 process . exit ( 0 ) ;
241241 }
242242} ) ( ) ;
0 commit comments