33
44import { GeneratedSchemaRegistryClient } from "./generated/generatedSchemaRegistryClient" ;
55import { TokenCredential } from "@azure/core-auth" ;
6+ import { createTracingClient , TracingClient } from "@azure/core-tracing" ;
67import {
78 bearerTokenAuthenticationPolicy ,
89 InternalPipelineOptions ,
@@ -19,7 +20,7 @@ import {
1920 SchemaProperties ,
2021 Schema ,
2122} from "./models" ;
22- import { DEFAULT_SCOPE } from "./constants" ;
23+ import { DEFAULT_SCOPE , SDK_VERSION } from "./constants" ;
2324import { logger } from "./logger" ;
2425
2526/**
@@ -30,7 +31,10 @@ export class SchemaRegistryClient implements SchemaRegistry {
3031 readonly fullyQualifiedNamespace : string ;
3132
3233 /** Underlying autorest generated client. */
33- private readonly client : GeneratedSchemaRegistryClient ;
34+ private readonly _client : GeneratedSchemaRegistryClient ;
35+
36+ /** The tracing client */
37+ private readonly _tracing : TracingClient ;
3438
3539 /**
3640 * Creates a new client for Azure Schema Registry service.
@@ -56,14 +60,20 @@ export class SchemaRegistryClient implements SchemaRegistry {
5660 } ,
5761 } ;
5862
59- this . client = new GeneratedSchemaRegistryClient ( this . fullyQualifiedNamespace , {
63+ this . _client = new GeneratedSchemaRegistryClient ( this . fullyQualifiedNamespace , {
6064 endpoint : this . fullyQualifiedNamespace ,
6165 apiVersion : options . apiVersion ,
6266 ...internalPipelineOptions ,
6367 } ) ;
6468
69+ this . _tracing = createTracingClient ( {
70+ namespace : "Microsoft.EventHub" ,
71+ packageName : "@azure/schema-registry" ,
72+ packageVersion : SDK_VERSION ,
73+ } ) ;
74+
6575 const authPolicy = bearerTokenAuthenticationPolicy ( { credential, scopes : DEFAULT_SCOPE } ) ;
66- this . client . pipeline . addPolicy ( authPolicy ) ;
76+ this . _client . pipeline . addPolicy ( authPolicy ) ;
6777 }
6878
6979 /**
@@ -76,20 +86,25 @@ export class SchemaRegistryClient implements SchemaRegistry {
7686 * @param schema - Schema to register.
7787 * @returns Registered schema's ID.
7888 */
79- async registerSchema (
89+ registerSchema (
8090 schema : SchemaDescription ,
81- options ? : RegisterSchemaOptions
91+ options : RegisterSchemaOptions = { }
8292 ) : Promise < SchemaProperties > {
8393 const { groupName, name : schemaName , definition : schemaContent , format } = schema ;
84- return this . client . schema
85- . register (
86- groupName ,
87- schemaName ,
88- `application/json; serialization=${ format } ` ,
89- schemaContent ,
90- options
91- )
92- . then ( convertSchemaIdResponse ( format ) ) ;
94+ return this . _tracing . withSpan (
95+ "SchemaRegistryClient.registerSchema" ,
96+ options ,
97+ ( updatedOptions ) =>
98+ this . _client . schema
99+ . register (
100+ groupName ,
101+ schemaName ,
102+ `application/json; serialization=${ format } ` ,
103+ schemaContent ,
104+ updatedOptions
105+ )
106+ . then ( convertSchemaIdResponse ( format ) )
107+ ) ;
93108 }
94109
95110 /**
@@ -99,20 +114,25 @@ export class SchemaRegistryClient implements SchemaRegistry {
99114 * @param schema - Schema to match.
100115 * @returns Matched schema's ID.
101116 */
102- async getSchemaProperties (
117+ getSchemaProperties (
103118 schema : SchemaDescription ,
104- options ? : GetSchemaPropertiesOptions
119+ options : GetSchemaPropertiesOptions = { }
105120 ) : Promise < SchemaProperties > {
106121 const { groupName, name : schemaName , definition : schemaContent , format } = schema ;
107- return this . client . schema
108- . queryIdByContent (
109- groupName ,
110- schemaName ,
111- `application/json; serialization=${ format } ` ,
112- schemaContent ,
113- options
114- )
115- . then ( convertSchemaIdResponse ( format ) ) ;
122+ return this . _tracing . withSpan (
123+ "SchemaRegistryClient.getSchemaProperties" ,
124+ options ,
125+ ( updatedOptions ) =>
126+ this . _client . schema
127+ . queryIdByContent (
128+ groupName ,
129+ schemaName ,
130+ `application/json; serialization=${ format } ` ,
131+ schemaContent ,
132+ updatedOptions
133+ )
134+ . then ( convertSchemaIdResponse ( format ) )
135+ ) ;
116136 }
117137
118138 /**
@@ -132,7 +152,9 @@ export class SchemaRegistryClient implements SchemaRegistry {
132152 * @param schemaId - Unique schema ID.
133153 * @returns Schema with given ID.
134154 */
135- async getSchema ( schemaId : string , options ?: GetSchemaOptions ) : Promise < Schema > {
136- return this . client . schema . getById ( schemaId , options ) . then ( convertSchemaResponse ) ;
155+ getSchema ( schemaId : string , options : GetSchemaOptions = { } ) : Promise < Schema > {
156+ return this . _tracing . withSpan ( "SchemaRegistryClient.getSchema" , options , ( updatedOptions ) =>
157+ this . _client . schema . getById ( schemaId , updatedOptions ) . then ( convertSchemaResponse )
158+ ) ;
137159 }
138160}
0 commit comments