Skip to content

Commit b6d1ad1

Browse files
authored
[Schema Registry] Use tracing (Azure#21256)
* [Schema Registry] Use tracing * address feedback * address feedback
1 parent 6256e86 commit b6d1ad1

File tree

4 files changed

+64
-29
lines changed

4 files changed

+64
-29
lines changed

sdk/schemaregistry/schema-registry/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.0.2 (Unreleased)
44

55
### Features Added
6+
- Added support for distributed tracing using OpenTelemetry - please refer to the [@azure/opentelemetry-instrumentation-azure-sdk](https://www.npmjs.com/package/@azure/opentelemetry-instrumentation-azure-sdk) package for instructions.
67

78
### Breaking Changes
89

sdk/schemaregistry/schema-registry/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
{
4949
"path": "swagger/README.md",
5050
"prefix": "package-version"
51+
},
52+
{
53+
"path": "src/constants.ts",
54+
"prefix": "SDK_VERSION"
5155
}
5256
]
5357
},
@@ -83,7 +87,7 @@
8387
"@azure/core-rest-pipeline": "^1.1.0",
8488
"@azure/core-client": "^1.0.0",
8589
"@azure/core-auth": "^1.3.0",
86-
"@azure/core-tracing": "1.0.0-preview.13",
90+
"@azure/core-tracing": "^1.0.0",
8791
"@azure/logger": "^1.0.0",
8892
"tslib": "^2.2.0"
8993
},
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT license.
33

4+
/**
5+
* @internal
6+
*/
47
export const DEFAULT_SCOPE = "https://eventhubs.azure.net/.default";
8+
9+
/**
10+
* @internal
11+
*/
12+
export const SDK_VERSION = "1.0.2";

sdk/schemaregistry/schema-registry/src/schemaRegistryClient.ts

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { GeneratedSchemaRegistryClient } from "./generated/generatedSchemaRegistryClient";
55
import { TokenCredential } from "@azure/core-auth";
6+
import { createTracingClient, TracingClient } from "@azure/core-tracing";
67
import {
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";
2324
import { 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

Comments
 (0)