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

feature/observability #427

Merged
merged 15 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@
],
"scripts": {
"build": "npm run build:cjs && npm run build:es",
"build:watch": "npm run build:watch:cjs & npm run build:watch:es",
"build:cjs": "tsc -b packages/test/tsconfig.cjs.json",
"build:watch:cjs": "tsc -b packages/test/tsconfig.cjs.json -w",
"build:es": "tsc -b packages/test/tsconfig.es.json",
"build:watch:es": "tsc -b packages/test/tsconfig.es.json -w",
"test": "lerna run test --parallel"
}
}
91 changes: 46 additions & 45 deletions packages/abstractions/package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
{
"name": "@microsoft/kiota-abstractions",
"version": "1.0.0-preview.7",
"description": "Core abstractions for kiota generated libraries in TypeScript and JavaScript",
"main": "dist/cjs/src/index.js",
"files": [
"src",
"dist"
],
"module": "dist/es/src/index.js",
"types": "dist/cjs/src/index.d.ts",
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.es.json",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"clean": "rm -r ./dist",
"karma": "npm run rollup && karma start --single-run --browsers ChromeHeadless karma.conf.js",
"rollup": "rollup -c",
"test": "npm run build && mocha 'dist/cjs/test/common/**/*.js'"
},
"repository": "git://github.com/microsoft/kiota-typescript.git",
"keywords": [
"kiota",
"openAPI",
"Microsoft",
"Graph"
],
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/kiota-typescript/issues"
},
"homepage": "https://github.com/microsoft/kiota#readme",
"devDependencies": {
"@types/node": "^18.0.0",
"@types/uri-template-lite": "^19.12.1",
"@types/uuid": "^8.3.4"
},
"dependencies": {
"tinyduration": "^3.2.2",
"tslib": "^2.3.1",
"uri-template-lite": "^22.1.0",
"uuid": "^9.0.0"
}
"name": "@microsoft/kiota-abstractions",
"version": "1.0.0-preview.8",
"description": "Core abstractions for kiota generated libraries in TypeScript and JavaScript",
"main": "dist/cjs/src/index.js",
"files": [
"src",
"dist"
],
"module": "dist/es/src/index.js",
"types": "dist/cjs/src/index.d.ts",
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.es.json",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"clean": "rm -r ./dist",
"karma": "npm run rollup && karma start --single-run --browsers ChromeHeadless karma.conf.js",
"rollup": "rollup -c",
"test": "npm run build && mocha 'dist/cjs/test/common/**/*.js'"
},
"repository": "git://github.com/microsoft/kiota-typescript.git",
"keywords": [
"kiota",
"openAPI",
"Microsoft",
"Graph"
],
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/kiota-typescript/issues"
},
"homepage": "https://github.com/microsoft/kiota#readme",
"devDependencies": {
"@types/node": "^18.0.0",
"@types/uri-template-lite": "^19.12.1",
"@types/uuid": "^8.3.4"
},
"dependencies": {
"@opentelemetry/api": "^1.2.0",
"tinyduration": "^3.2.2",
"tslib": "^2.3.1",
"uri-template-lite": "^22.1.0",
"uuid": "^9.0.0"
}
}
129 changes: 76 additions & 53 deletions packages/abstractions/src/requestInformation.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { trace } from "@opentelemetry/api";
import * as urlTpl from "uri-template-lite";

import { DateOnly } from "./dateOnly";
Expand Down Expand Up @@ -94,8 +95,10 @@ export class RequestInformation {
delete this._requestOptions[option.getKey()];
});
}
private static binaryContentType = "application/octet-stream";
private static contentTypeHeader = "Content-Type";
private static readonly binaryContentType = "application/octet-stream";
private static readonly contentTypeHeader = "Content-Type";
private static readonly tracerKey = "@microsoft/kiota-abstractions";
private static readonly requestTypeKey = "com.microsoft.kiota.request.type";
/**
* Sets the request body from a model with the specified content type.
* @param value the models.
Expand All @@ -108,20 +111,30 @@ export class RequestInformation {
contentType?: string | undefined,
value?: T[] | T
): void => {
const writer = this.getSerializationWriter(
requestAdapter,
contentType,
value
);
if (!this.headers) {
this.headers = {};
}
if (Array.isArray(value)) {
writer.writeCollectionOfObjectValues(undefined, value);
} else {
writer.writeObjectValue(undefined, value);
}
this.setContentAndContentType(writer, contentType);
trace
.getTracer(RequestInformation.tracerKey)
.startActiveSpan("setContentFromParsable", (span) => {
try {
const writer = this.getSerializationWriter(
requestAdapter,
contentType,
value
);
if (!this.headers) {
this.headers = {};
}
if (Array.isArray(value)) {
span.setAttribute(RequestInformation.requestTypeKey, "object[]");
writer.writeCollectionOfObjectValues(undefined, value);
} else {
span.setAttribute(RequestInformation.requestTypeKey, "object");
writer.writeObjectValue(undefined, value);
}
this.setContentAndContentType(writer, contentType);
} finally {
span.end();
}
});
};
private setContentAndContentType = (
writer: SerializationWriter,
Expand Down Expand Up @@ -158,44 +171,54 @@ export class RequestInformation {
contentType?: string | undefined,
value?: T[] | T
): void => {
const writer = this.getSerializationWriter(
requestAdapter,
contentType,
value
);
if (!this.headers) {
this.headers = {};
}
trace
.getTracer(RequestInformation.tracerKey)
.startActiveSpan("setContentFromScalar", (span) => {
try {
const writer = this.getSerializationWriter(
requestAdapter,
contentType,
value
);
if (!this.headers) {
this.headers = {};
}

if (Array.isArray(value)) {
writer.writeCollectionOfPrimitiveValues(undefined, value);
} else {
const valueType = typeof value;
if (!value) {
writer.writeNullValue(undefined);
} else if (valueType === "boolean") {
writer.writeBooleanValue(undefined, value as any as boolean);
} else if (valueType === "string") {
writer.writeStringValue(undefined, value as any as string);
} else if (value instanceof Date) {
writer.writeDateValue(undefined, value as any as Date);
} else if (value instanceof DateOnly) {
writer.writeDateOnlyValue(undefined, value as any as DateOnly);
} else if (value instanceof TimeOnly) {
writer.writeTimeOnlyValue(undefined, value as any as TimeOnly);
} else if (value instanceof Duration) {
writer.writeDurationValue(undefined, value as any as Duration);
} else if (valueType === "number") {
writer.writeNumberValue(undefined, value as any as number);
} else if (Array.isArray(value)) {
writer.writeCollectionOfPrimitiveValues(undefined, value);
} else {
throw new Error(
`encountered unknown value type during serialization ${valueType}`
);
}
}
this.setContentAndContentType(writer, contentType);
if (Array.isArray(value)) {
span.setAttribute(RequestInformation.requestTypeKey, "[]");
writer.writeCollectionOfPrimitiveValues(undefined, value);
} else {
const valueType = typeof value;
span.setAttribute(RequestInformation.requestTypeKey, valueType);
if (!value) {
writer.writeNullValue(undefined);
} else if (valueType === "boolean") {
writer.writeBooleanValue(undefined, value as any as boolean);
} else if (valueType === "string") {
writer.writeStringValue(undefined, value as any as string);
} else if (value instanceof Date) {
writer.writeDateValue(undefined, value as any as Date);
} else if (value instanceof DateOnly) {
writer.writeDateOnlyValue(undefined, value as any as DateOnly);
} else if (value instanceof TimeOnly) {
writer.writeTimeOnlyValue(undefined, value as any as TimeOnly);
} else if (value instanceof Duration) {
writer.writeDurationValue(undefined, value as any as Duration);
} else if (valueType === "number") {
writer.writeNumberValue(undefined, value as any as number);
} else if (Array.isArray(value)) {
writer.writeCollectionOfPrimitiveValues(undefined, value);
} else {
throw new Error(
`encountered unknown value type during serialization ${valueType}`
);
}
}
this.setContentAndContentType(writer, contentType);
} finally {
span.end();
}
});
};
/**
* Sets the request body to be a binary stream.
Expand Down
77 changes: 39 additions & 38 deletions packages/authentication/azure/package.json
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
{
"name": "@microsoft/kiota-authentication-azure",
"version": "1.0.0-preview.5",
"description": "Authentication provider for Kiota using Azure Identity",
"main": "dist/cjs/src/index.js",
"module": "dist/es/src/index.js",
"types": "dist/cjs/src/index.d.ts",
"files": [
"src",
"dist"
],
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -b tsconfig.cjs.json",
"build:esm": "tsc -b tsconfig.es.json",
"test": "npm run build && mocha 'dist/cjs/test/**/*.js'",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"clean": "rm -r ./dist"
},
"repository": "git://github.com/microsoft/kiota-typescript.git",
"keywords": [
"Kiota",
"OpenApi",
"Azure",
"Authentication",
"OAuth"
],
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/kiota-typescript/issues"
},
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
"dependencies": {
"@azure/core-auth": "^1.3.2",
"@microsoft/kiota-abstractions": "1.0.0-preview.7",
"tslib": "^2.3.1"
}
"name": "@microsoft/kiota-authentication-azure",
"version": "1.0.0-preview.6",
"description": "Authentication provider for Kiota using Azure Identity",
"main": "dist/cjs/src/index.js",
"module": "dist/es/src/index.js",
"types": "dist/cjs/src/index.d.ts",
"files": [
"src",
"dist"
],
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"build:cjs": "tsc -b tsconfig.cjs.json",
"build:esm": "tsc -b tsconfig.es.json",
"test": "npm run build && mocha 'dist/cjs/test/**/*.js'",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"clean": "rm -r ./dist"
},
"repository": "git://github.com/microsoft/kiota-typescript.git",
"keywords": [
"Kiota",
"OpenApi",
"Azure",
"Authentication",
"OAuth"
],
"author": "Microsoft",
"license": "MIT",
"bugs": {
"url": "https://github.com/microsoft/kiota-typescript/issues"
},
"homepage": "https://github.com/microsoft/kiota-typescript#readme",
"dependencies": {
"@azure/core-auth": "^1.3.2",
"@microsoft/kiota-abstractions": "^1.0.0-preview.8",
"@opentelemetry/api": "^1.2.0",
"tslib": "^2.3.1"
}
}
Loading