Skip to content

Commit ba8ab7b

Browse files
committed
Improve type definitions to ensure ConnectionInfo is valid
One field of ConnectionInfo needs to be set otherwise SDK will reject to create a tracer. Fixes: #1
1 parent d5b4a70 commit ba8ab7b

File tree

6 files changed

+101
-36
lines changed

6 files changed

+101
-36
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ see also [Releases](https://github.com/Dynatrace/OneAgent-SDK-for-NodeJs/release
487487

488488
|Version|Description |
489489
|:------|:-------------------------------------------|
490+
|1.2.1 |improve type definitions |
490491
|1.2.0 |add support for custom request attributes |
491492
|1.1.0 |add setResultData() for SQL Database tracer |
492493
|1.0.3 |early access to beta |

package.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dynatrace/oneagent-sdk",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Node.js SDK for Dynatrace OneAgent",
55
"engines": {
66
"node": ">= 4.0.0"
@@ -22,10 +22,7 @@
2222
"bugs": {
2323
"url": "https://github.com/Dynatrace/OneAgent-SDK-for-NodeJs/issues/"
2424
},
25-
"repository": {
26-
"type": "git",
27-
"url": "git+https://github.com/Dynatrace/OneAgent-SDK-for-NodeJs.git"
28-
},
25+
"repository": "Dynatrace/OneAgent-SDK-for-NodeJs",
2926
"homepage": "https://www.dynatrace.com/technologies/nodejs-monitoring/",
3027
"keywords": [
3128
"dynatrace",
@@ -38,15 +35,15 @@
3835
"adk"
3936
],
4037
"devDependencies": {
41-
"@types/mocha": "5.2.2",
42-
"@types/node": "10.3.3",
43-
"@types/sinon": "5.0.1",
38+
"@types/mocha": "5.2.5",
39+
"@types/node": "10.12.12",
40+
"@types/sinon": "5.0.7",
4441
"mocha": "5.2.0",
4542
"rimraf": "2.6.2",
46-
"sinon": "6.0.0",
47-
"source-map-support": "0.5.6",
48-
"tslint": "5.10.0",
49-
"typescript": "2.9.2"
43+
"sinon": "7.1.1",
44+
"source-map-support": "0.5.9",
45+
"tslint": "5.11.0",
46+
"typescript": "3.2.1"
5047
},
5148
"author": "Dynatrace",
5249
"license": "Apache-2.0"

samples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sdksamples",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "Samples showing API for OneAgent SDK",
55
"engines": {
66
"node": ">= 8.0.0"
@@ -11,7 +11,7 @@
1111
"customrequestattribute": "node CustomRequestAttributes/CustomRequestAttributesSample.js"
1212
},
1313
"dependencies": {
14-
"@dynatrace/oneagent-sdk": "1.2.0"
14+
"@dynatrace/oneagent-sdk": "1.2.1"
1515
},
1616
"repository": {
1717
"type": "git",

src/Sdk.ts

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,15 @@ export const enum ChannelType {
7979
export interface ConnectionInfo {
8080
/// The hostname/IP of the server-side in case a TCP/IP connection is used
8181
host?: string;
82-
// The port in case a TCP/IP connection is used
82+
/// The port in case a TCP/IP connection is used
8383
port?: number;
8484

85-
8685
/// The path of the UNIX domain socket file
8786
socketPath?: string;
8887

89-
9088
/// The name of the pipe
9189
pipeName?: string;
9290

93-
9491
/// Set this field if no other field can be set
9592
channelType?: ChannelType;
9693
}
@@ -261,14 +258,33 @@ export interface OutgoingTaggable {
261258
/**
262259
* Description of a database.
263260
*/
264-
export interface DatabaseInfo extends ConnectionInfo {
261+
export interface DatabaseInfoCommon extends ConnectionInfo {
265262
/// The name of the database
266263
name: string;
267264

268265
/// The database vendor name (e.a. Oracle, MySQL, ...) can be an user defined name. If possible use a constant defined in DatabaseVendor.
269266
vendor: string;
270267
}
271268

269+
export interface DatabaseInfoTcp extends DatabaseInfoCommon {
270+
host: string;
271+
port?: number;
272+
}
273+
274+
export interface DatabaseInfoDomainSocket extends DatabaseInfoCommon {
275+
socketPath: string;
276+
}
277+
278+
export interface DatabaseInfoPipe extends DatabaseInfoCommon {
279+
pipeName: string;
280+
}
281+
282+
export interface DatabaseInfoChannelType extends DatabaseInfoCommon {
283+
channelType: ChannelType;
284+
}
285+
286+
export type DatabaseInfo = DatabaseInfoTcp | DatabaseInfoDomainSocket | DatabaseInfoPipe | DatabaseInfoChannelType;
287+
272288
/**
273289
* Specifies the SQL DatabaseTracer start data
274290
*/
@@ -332,7 +348,7 @@ export interface IncomingRemoteCallTracer extends IncomingTracer {
332348
/**
333349
* Specifies the start data for an outgoing remote call.
334350
*/
335-
export interface OutgoingRemoteCallStartData extends ConnectionInfo {
351+
export interface OutgoingRemoteCallStartDataCommon extends ConnectionInfo {
336352
/// Name of the called remote method
337353
serviceMethod: string;
338354

@@ -350,6 +366,25 @@ export interface OutgoingRemoteCallStartData extends ConnectionInfo {
350366
protocolName?: string;
351367
}
352368

369+
export interface OutgoingRemoteCallStartDataTcp extends OutgoingRemoteCallStartDataCommon {
370+
host: string;
371+
port?: number;
372+
}
373+
374+
export interface OutgoingRemoteCallStartDataDomainSocket extends OutgoingRemoteCallStartDataCommon {
375+
socketPath: string;
376+
}
377+
378+
export interface OutgoingRemoteCallStartDataPipe extends OutgoingRemoteCallStartDataCommon {
379+
pipeName: string;
380+
}
381+
382+
export interface OutgoingRemoteCallStartDataChannelType extends OutgoingRemoteCallStartDataCommon {
383+
channelType: ChannelType;
384+
}
385+
386+
export type OutgoingRemoteCallStartData = OutgoingRemoteCallStartDataTcp | OutgoingRemoteCallStartDataDomainSocket | OutgoingRemoteCallStartDataPipe | OutgoingRemoteCallStartDataChannelType;
387+
353388
/**
354389
* Tracer for an outgoing remote call.
355390
* Created by {@link traceOutgoingRemoteCall}

src/Stub.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ import * as Sdk from "./Sdk";
1818

1919
// ============================================================================
2020

21+
const useNewBufferApi = typeof(Buffer.alloc) === "function";
22+
23+
function BufferFrom(str: string, encoding?: string): Buffer {
24+
// tslint:disable-next-line:deprecation
25+
return useNewBufferApi ? Buffer.from(str, encoding) : new Buffer(str, encoding);
26+
}
2127

2228
class DummyTracer implements Sdk.Tracer {
2329
public start<R>(handler: (...args: any[]) => R, ...args: any[]): R {
@@ -57,7 +63,7 @@ class DummyOutgoingTaggableTracer extends DummyOutgoingTracer implements Sdk.Tra
5763
return "";
5864
}
5965
public getDynatraceByteTag(): Buffer {
60-
return new Buffer("");
66+
return BufferFrom("");
6167
}
6268
}
6369

tslint.json

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"statements"
99
],
1010
"comment-format": false,
11+
"deprecation": true,
1112
"no-empty-interface": false,
1213
"indent": [
1314
true,
@@ -24,28 +25,45 @@
2425
true,
2526
{
2627
"order": [
27-
"public-constructor",
28-
"public-static-method",
29-
"public-static-field",
30-
"public-instance-method",
31-
"public-instance-field",
32-
"protected-constructor",
33-
"protected-static-method",
34-
"protected-static-field",
35-
"protected-instance-method",
36-
"protected-instance-field",
37-
"private-constructor",
38-
"private-static-method",
39-
"private-static-field",
40-
"private-instance-method",
41-
"private-instance-field"
28+
{
29+
"name": "public",
30+
"kinds": [
31+
"public-static-field",
32+
"public-static-method",
33+
"public-instance-field",
34+
"public-constructor",
35+
"public-instance-method"
36+
]
37+
},
38+
{
39+
"name": "protected",
40+
"kinds": [
41+
"protected-static-field",
42+
"protected-static-method",
43+
"protected-instance-field",
44+
"protected-constructor",
45+
"protected-instance-method"
46+
]
47+
},
48+
{
49+
"name": "private",
50+
"kinds": [
51+
"private-static-field",
52+
"private-static-method",
53+
"private-instance-field",
54+
"private-constructor",
55+
"private-instance-method"
56+
]
57+
}
4258
]
4359
}
4460
],
4561
"no-consecutive-blank-lines": [
4662
true,
4763
5
4864
],
65+
"no-unnecessary-type-assertion": true,
66+
"no-unused-expression": [true, "allow-new"],
4967
"object-literal-shorthand": false,
5068
"object-literal-sort-keys": false,
5169
"ordered-imports": false,
@@ -58,10 +76,18 @@
5876
]
5977
},
6078
"jsRules": {
79+
"indent": [
80+
true,
81+
"tabs"
82+
],
6183
"max-line-length": [
6284
true,
6385
200
6486
],
87+
"no-consecutive-blank-lines": [
88+
true,
89+
5
90+
],
6591
"object-literal-sort-keys": false,
6692
"trailing-comma": [
6793
true,

0 commit comments

Comments
 (0)