Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Prototype Code - Do NOT Merge #4506

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
1bbfeca
Initial commit
sarangan12 Jul 25, 2019
513a9aa
Include Tracing to Rush & as Dep to Keys Bild Fine
sarangan12 Jul 25, 2019
067b8fa
Minor change to package.json file
sarangan12 Jul 25, 2019
2db9c72
Temporary Sample Changes. REMOVE LATER
sarangan12 Jul 25, 2019
d275d55
Revert samples
sarangan12 Jul 25, 2019
6be74ef
Changes to make it work with sample
sarangan12 Jul 25, 2019
2ccba36
Further changes
sarangan12 Jul 26, 2019
444dd20
Add spanOptions as sep field in msRequestoptions
sarangan12 Jul 26, 2019
c4a8394
Adding serializing to the span options
sarangan12 Jul 26, 2019
fdee6b0
Adding parent child relationship to the span
sarangan12 Jul 26, 2019
8280076
Additional changes
sarangan12 Jul 29, 2019
f28a882
Adding code for create/delete
sarangan12 Jul 29, 2019
c4a0305
Rush Update full
sarangan12 Jul 29, 2019
71205ab
Fix call to OpenCensus
sarangan12 Jul 31, 2019
0fed109
Add span to all(almost) apis
sarangan12 Aug 1, 2019
9af78bf
Minor Optimization
sarangan12 Aug 1, 2019
aca53f5
Further optimization
sarangan12 Aug 1, 2019
25ba6f2
Implement NoOp
sarangan12 Aug 1, 2019
6c3de84
Add NoOp Impl
sarangan12 Aug 1, 2019
2934dd4
Update core-tracing to follow template
ramya-rao-a Aug 2, 2019
328d8cd
Merge pull request #1 from ramya-rao-a/tracing
sarangan12 Aug 2, 2019
8c870c4
Resolving conflict
sarangan12 Aug 2, 2019
4135837
Merge remote-tracking branch 'origin/master' into Telemetry
sarangan12 Aug 2, 2019
ae1822f
Adding cloning
sarangan12 Aug 2, 2019
858af9e
Adding cloning to remaining APIs
sarangan12 Aug 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 190 additions & 109 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@
{
"packageName": "@azure/template",
"projectFolder": "sdk/template/template"
},
{
"packageName": "@azure/core-tracing",
"projectFolder": "sdk/core/core-tracing"
}
]
}
136 changes: 98 additions & 38 deletions sdk/core/core-http/lib/webResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,21 @@ import { HttpOperationResponse } from "./httpOperationResponse";
import { OperationResponse } from "./operationResponse";
import { ProxySettings } from "./serviceClient";

export type HttpMethods = "GET" | "PUT" | "POST" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS" | "TRACE";
export type HttpRequestBody = Blob | string | ArrayBuffer | ArrayBufferView | (() => NodeJS.ReadableStream);
export type HttpMethods =
| "GET"
| "PUT"
| "POST"
| "DELETE"
| "PATCH"
| "HEAD"
| "OPTIONS"
| "TRACE";
export type HttpRequestBody =
| Blob
| string
| ArrayBuffer
| ArrayBufferView
| (() => NodeJS.ReadableStream);

/**
* Fired in response to upload or download progress.
Expand All @@ -19,7 +32,7 @@ export type TransferProgressEvent = {
/**
* The number of bytes loaded so far.
*/
loadedBytes: number
loadedBytes: number;
};

/**
Expand All @@ -28,8 +41,16 @@ export type TransferProgressEvent = {
*/
export interface AbortSignalLike {
readonly aborted: boolean;
addEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
removeEventListener(type: "abort", listener: (this: AbortSignalLike, ev: any) => any, options?: any): void;
addEventListener(
type: "abort",
listener: (this: AbortSignalLike, ev: any) => any,
options?: any
): void;
removeEventListener(
type: "abort",
listener: (this: AbortSignalLike, ev: any) => any,
options?: any
): void;
}

/**
Expand Down Expand Up @@ -59,9 +80,12 @@ export class WebResource {
* HttpOperationResponse combination. If this is undefined, then a simple status code lookup will
* be used.
*/
operationResponseGetter?: (operationSpec: OperationSpec, response: HttpOperationResponse) => (undefined | OperationResponse);
operationResponseGetter?: (
operationSpec: OperationSpec,
response: HttpOperationResponse
) => undefined | OperationResponse;
formData?: any;
query?: { [key: string]: any; };
query?: { [key: string]: any };
operationSpec?: OperationSpec;
withCredentials: boolean;
timeout: number;
Expand All @@ -79,20 +103,20 @@ export class WebResource {
url?: string,
method?: HttpMethods,
body?: any,
query?: { [key: string]: any; },
headers?: { [key: string]: any; } | HttpHeaders,
query?: { [key: string]: any },
headers?: { [key: string]: any } | HttpHeaders,
streamResponseBody?: boolean,
withCredentials?: boolean,
abortSignal?: AbortSignalLike,
timeout?: number,
onUploadProgress?: (progress: TransferProgressEvent) => void,
onDownloadProgress?: (progress: TransferProgressEvent) => void,
proxySettings?: ProxySettings) {

proxySettings?: ProxySettings
) {
this.streamResponseBody = streamResponseBody;
this.url = url || "";
this.method = method || "GET";
this.headers = (headers instanceof HttpHeaders ? headers : new HttpHeaders(headers));
this.headers = headers instanceof HttpHeaders ? headers : new HttpHeaders(headers);
this.body = body;
this.query = query;
this.formData = undefined;
Expand Down Expand Up @@ -133,18 +157,22 @@ export class WebResource {
}

if (options.url && options.pathTemplate) {
throw new Error("options.url and options.pathTemplate are mutually exclusive. Please provide exactly one of them.");
throw new Error(
"options.url and options.pathTemplate are mutually exclusive. Please provide exactly one of them."
);
}


if ((options.pathTemplate == undefined || typeof options.pathTemplate.valueOf() !== "string") && (options.url == undefined || typeof options.url.valueOf() !== "string")) {
if (
(options.pathTemplate == undefined || typeof options.pathTemplate.valueOf() !== "string") &&
(options.url == undefined || typeof options.url.valueOf() !== "string")
) {
throw new Error("Please provide exactly one of options.pathTemplate or options.url.");
}

// set the url if it is provided.
if (options.url) {
if (typeof options.url !== "string") {
throw new Error("options.url must be of type \"string\".");
throw new Error('options.url must be of type "string".');
}
this.url = options.url;
}
Expand All @@ -153,35 +181,55 @@ export class WebResource {
if (options.method) {
const validMethods = ["GET", "PUT", "HEAD", "DELETE", "OPTIONS", "POST", "PATCH", "TRACE"];
if (validMethods.indexOf(options.method.toUpperCase()) === -1) {
throw new Error("The provided method \"" + options.method + "\" is invalid. Supported HTTP methods are: " + JSON.stringify(validMethods));
throw new Error(
'The provided method "' +
options.method +
'" is invalid. Supported HTTP methods are: ' +
JSON.stringify(validMethods)
);
}
}
this.method = (options.method.toUpperCase() as HttpMethods);
this.method = options.method.toUpperCase() as HttpMethods;

// construct the url if path template is provided
if (options.pathTemplate) {
const { pathTemplate, pathParameters } = options;
if (typeof pathTemplate !== "string") {
throw new Error("options.pathTemplate must be of type \"string\".");
throw new Error('options.pathTemplate must be of type "string".');
}
if (!options.baseUrl) {
options.baseUrl = "https://management.azure.com";
}
const baseUrl = options.baseUrl;
let url = baseUrl + (baseUrl.endsWith("/") ? "" : "/") + (pathTemplate.startsWith("/") ? pathTemplate.slice(1) : pathTemplate);
const segments = url.match(/({\w*\s*\w*})/ig);
let url =
baseUrl +
(baseUrl.endsWith("/") ? "" : "/") +
(pathTemplate.startsWith("/") ? pathTemplate.slice(1) : pathTemplate);
const segments = url.match(/({\w*\s*\w*})/gi);
if (segments && segments.length) {
if (!pathParameters) {
throw new Error(`pathTemplate: ${pathTemplate} has been provided. Hence, options.pathParameters must also be provided.`);
throw new Error(
`pathTemplate: ${pathTemplate} has been provided. Hence, options.pathParameters must also be provided.`
);
}
segments.forEach(function (item) {
segments.forEach(function(item) {
const pathParamName = item.slice(1, -1);
const pathParam = (pathParameters as { [key: string]: any })[pathParamName];
if (pathParam === null || pathParam === undefined || !(typeof pathParam === "string" || typeof pathParam === "object")) {
throw new Error(`pathTemplate: ${pathTemplate} contains the path parameter ${pathParamName}` +
` however, it is not present in ${pathParameters} - ${JSON.stringify(pathParameters, undefined, 2)}.` +
`The value of the path parameter can either be a "string" of the form { ${pathParamName}: "some sample value" } or ` +
`it can be an "object" of the form { "${pathParamName}": { value: "some sample value", skipUrlEncoding: true } }.`);
if (
pathParam === null ||
pathParam === undefined ||
!(typeof pathParam === "string" || typeof pathParam === "object")
) {
throw new Error(
`pathTemplate: ${pathTemplate} contains the path parameter ${pathParamName}` +
` however, it is not present in ${pathParameters} - ${JSON.stringify(
pathParameters,
undefined,
2
)}.` +
`The value of the path parameter can either be a "string" of the form { ${pathParamName}: "some sample value" } or ` +
`it can be an "object" of the form { "${pathParamName}": { value: "some sample value", skipUrlEncoding: true } }.`
);
}

if (typeof pathParam.valueOf() === "string") {
Expand All @@ -190,7 +238,9 @@ export class WebResource {

if (typeof pathParam.valueOf() === "object") {
if (!pathParam.value) {
throw new Error(`options.pathParameters[${pathParamName}] is of type "object" but it does not contain a "value" property.`);
throw new Error(
`options.pathParameters[${pathParamName}] is of type "object" but it does not contain a "value" property.`
);
}
if (pathParam.skipUrlEncoding) {
url = url.replace(item, pathParam.value);
Expand All @@ -207,9 +257,11 @@ export class WebResource {
if (options.queryParameters) {
const queryParameters = options.queryParameters;
if (typeof queryParameters !== "object") {
throw new Error(`options.queryParameters must be of type object. It should be a JSON object ` +
`of "query-parameter-name" as the key and the "query-parameter-value" as the value. ` +
`The "query-parameter-value" may be fo type "string" or an "object" of the form { value: "query-parameter-value", skipUrlEncoding: true }.`);
throw new Error(
`options.queryParameters must be of type object. It should be a JSON object ` +
`of "query-parameter-name" as the key and the "query-parameter-value" as the value. ` +
`The "query-parameter-value" may be fo type "string" or an "object" of the form { value: "query-parameter-value", skipUrlEncoding: true }.`
);
}
// append question mark if it is not present in the url
if (this.url && this.url.indexOf("?") === -1) {
Expand All @@ -225,10 +277,11 @@ export class WebResource {
if (typeof queryParam === "string") {
queryParams.push(queryParamName + "=" + encodeURIComponent(queryParam));
this.query[queryParamName] = encodeURIComponent(queryParam);
}
else if (typeof queryParam === "object") {
} else if (typeof queryParam === "object") {
if (!queryParam.value) {
throw new Error(`options.queryParameters[${queryParamName}] is of type "object" but it does not contain a "value" property.`);
throw new Error(
`options.queryParameters[${queryParamName}] is of type "object" but it does not contain a "value" property.`
);
}
if (queryParam.skipUrlEncoding) {
queryParams.push(queryParamName + "=" + queryParam.value);
Expand All @@ -239,7 +292,7 @@ export class WebResource {
}
}
}
}// end-of-for
} // end-of-for
// append the queryString
this.url += queryParams.join("&");
}
Expand Down Expand Up @@ -278,7 +331,11 @@ export class WebResource {
}
} else {
if (options.serializationMapper) {
this.body = new Serializer(options.mappers).serialize(options.serializationMapper, options.body, "requestBody");
this.body = new Serializer(options.mappers).serialize(
options.serializationMapper,
options.body,
"requestBody"
);
}
if (!options.disableJsonStringifyOnBody) {
this.body = JSON.stringify(options.body);
Expand Down Expand Up @@ -309,7 +366,8 @@ export class WebResource {
this.abortSignal,
this.timeout,
this.onUploadProgress,
this.onDownloadProgress);
this.onDownloadProgress
);

if (this.formData) {
result.formData = this.formData;
Expand Down Expand Up @@ -460,5 +518,7 @@ export interface RequestOptionsBase {
*/
onDownloadProgress?: (progress: TransferProgressEvent) => void;

spanOptions?: any;

[key: string]: any;
}
1 change: 1 addition & 0 deletions sdk/core/core-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"all": true
},
"dependencies": {
"@azure/core-tracing": "1.0.0-preview.1",
"@azure/core-auth": "1.0.0-preview.1",
"@types/tunnel": "^0.0.0",
"axios": "^0.19.0",
Expand Down
10 changes: 10 additions & 0 deletions sdk/core/core-tracing/.typings/karma.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as karma from "karma";

export type Config = karma.Config & {
rollupPreprocessor: any;
set: (config: ConfigOptions) => void;
}

export type ConfigOptions = karma.ConfigOptions & {
rollupPreprocessor: any;
}
4 changes: 4 additions & 0 deletions sdk/core/core-tracing/.typings/rollup-plugin-alias.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "rollup-plugin-alias" {
const alias(options: { [_: string]: string }) => void;
export default alias;
}
4 changes: 4 additions & 0 deletions sdk/core/core-tracing/.typings/rollup-plugin-commonjs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "rollup-plugin-commonjs" {
const commonjs(options?: any) => void;
export default commonjs;
}
4 changes: 4 additions & 0 deletions sdk/core/core-tracing/.typings/rollup-plugin-json.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "rollup-plugin-json" {
const json() => void;
export default json;
}
4 changes: 4 additions & 0 deletions sdk/core/core-tracing/.typings/rollup-plugin-multi-entry.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module 'rollup-plugin-multi-entry' {
const multiEntry: () => void;
export default multiEntry;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "rollup-plugin-node-resolve" {
const nodeResolve(options: { [_: string]: any }) => void;
export default nodeResolve;
}
4 changes: 4 additions & 0 deletions sdk/core/core-tracing/.typings/rollup-plugin-sourcemaps.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "rollup-plugin-sourcemaps" {
const sourcemaps() => void;
export default sourcemaps;
}
4 changes: 4 additions & 0 deletions sdk/core/core-tracing/.typings/rollup-plugin-visualizer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "rollup-plugin-visualizer" {
const visualizer(options?: { [_: string]: any }) => void;
export default visualizer;
}
1 change: 1 addition & 0 deletions sdk/core/core-tracing/Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
21 changes: 21 additions & 0 deletions sdk/core/core-tracing/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
23 changes: 23 additions & 0 deletions sdk/core/core-tracing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Azure Core HTTP client library for JS

This is the core HTTP pipeline for Azure SDK JavaScript libraries which work in the browser and Node.js. This library is primarily intended to be used in code generated by [AutoRest](https://github.com/Azure/Autorest).

## Getting started

Coming soon....

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

If you'd like to contribute to this library, please read the [contributing guide](../../../CONTRIBUTING.md) to learn more about how to build and test the code.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
Loading