How to use @dynatrace/oneagent-sdk - 10 common examples

To help you get started, we’ve selected a few @dynatrace/oneagent-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dynatrace / OneAgent-SDK-for-NodeJs / samples / RemoteCall / IncomingRemoteCallSample.js View on Github external
distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("IncomingRemoteCallSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("IncomingRemoteCallSample SDK warning: " + msg),
  error: (msg) => console.error("IncomingRemoteCallSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------

// Function actually processing the message
async function processMessage(message) {
  switch (message.method) {
    case "toUpper": return message.text.toUpperCase();
    case "toLower": return message.text.toLowerCase();
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / CustomRequestAttributes / CustomRequestAttributesSample.js View on Github external
distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("CustomRequestAttributesSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("CustomRequestAttributesSample SDK warning: " + msg),
  error: (msg) => console.error("CustomRequestAttributesSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------
const http = require("http");

// ----------------------------------------------------------------------------
const server = http.createServer(function onRequest(req, res) {
  // set attribute named "fooAttribute" with value "bar"
  Api.addCustomRequestAttribute("fooAttribute", "bar");
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / Database / DatabaseRequestSample.js View on Github external
distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("DatabaseRequestSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("DatabaseRequestSample SDK warning: " + msg),
  error: (msg) => console.error("DatabaseRequestSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------
const http = require("http");

// ----------------------------------------------------------------------------
// Simple simulation of a database...
class SomeDbConnection {
  query(sql, cb) {
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / RemoteCall / OutgoingRemoteCallSample.js View on Github external
distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("OutgoingRemoteCallSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("OutgoingRemoteCallSample SDK warning: " + msg),
  error: (msg) => console.error("OutgoingRemoteCallSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------
const cp = require("child_process");

let id = 0;
const map = new Map();

// start the remote call server
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / RemoteCall / IncomingRemoteCallSample.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("IncomingRemoteCallSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("IncomingRemoteCallSample SDK warning: " + msg),
  error: (msg) => console.error("IncomingRemoteCallSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------

// Function actually processing the message
async function processMessage(message) {
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / CustomRequestAttributes / CustomRequestAttributesSample.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("CustomRequestAttributesSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("CustomRequestAttributesSample SDK warning: " + msg),
  error: (msg) => console.error("CustomRequestAttributesSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------
const http = require("http");

// ----------------------------------------------------------------------------
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / Database / DatabaseRequestSample.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("DatabaseRequestSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("DatabaseRequestSample SDK warning: " + msg),
  error: (msg) => console.error("DatabaseRequestSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------
const http = require("http");

// ----------------------------------------------------------------------------
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / RemoteCall / OutgoingRemoteCallSample.js View on Github external
http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

"use strict";

// tslint:disable:no-console

// ----------------------------------------------------------------------------
const Sdk = require("@dynatrace/oneagent-sdk");
const Api = Sdk.createInstance();

// ----------------------------------------------------------------------------
if (Api.getCurrentState() !== Sdk.SDKState.ACTIVE) {
  console.error("OutgoingRemoteCallSample: SDK is not active!");
}

// install logging callbacks
Api.setLoggingCallbacks({
  warning: (msg) => console.error("OutgoingRemoteCallSample SDK warning: " + msg),
  error: (msg) => console.error("OutgoingRemoteCallSample SDK error: " + msg)
});

// ----------------------------------------------------------------------------
const cp = require("child_process");

let id = 0;
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / RemoteCall / OutgoingRemoteCallSample.js View on Github external
async function tracedOutgoingRemoteCall(method, data) {
  const tracer = Api.traceOutgoingRemoteCall({
    serviceEndpoint: "ChildProcess",
    serviceMethod: method,  // the name of the remote method called
    serviceName: "StringManipulator",
    channelType: Sdk.ChannelType.NAMED_PIPE
  });

  try {
    // start tracer, get dynatrace tag and trigger sending via doOutgoingRemoteCall()
    return await tracer.start(function triggerTaggedRemoteCall() {
      // getting a tag from tracer needs to be done after start()
      const dtTag = tracer.getDynatraceStringTag();
      // now trigger the actual remote call
      return doOutgoingRemoteCall(method, data, dtTag);
    });
  } catch (e) {
    tracer.error(e);
    throw e;
  } finally {
    tracer.end();
  }
github Dynatrace / OneAgent-SDK-for-NodeJs / samples / Database / DatabaseRequestSample.js View on Github external
// ----------------------------------------------------------------------------
// Create the connection to database
const dbConfig = {
  host: "localhost",
  port: 57615,
  user: "root",
  password: "12345",
  database: "TestDb"
};
const connection = somesqldb.createConnection(dbConfig);

// Static info describing the database
const dbInfo = {
  name: dbConfig.database,
  vendor: Sdk.DatabaseVendor.MARIADB,
  host: dbConfig.host,
  port: dbConfig.port
};

// Issue a traced SQL database request
function tracedSqlDatabaseRequest(sql, clientCb) {
  // create a SQL database tracer
  const tracer = Api.traceSQLDatabaseRequest(dbInfo, {
    statement: sql
  });

  // start tracer, calls connection.query(sql, cb) with connection set as this in query()
  tracer.startWithContext(connection.query, connection, sql, (err, results, fields) => {
    if (err) {
      // set the error on the tracer
      tracer.error(err);

@dynatrace/oneagent-sdk

Node.js SDK for Dynatrace OneAgent

Apache-2.0
Latest version published 2 years ago

Package Health Score

51 / 100
Full package analysis