ContextInfo

Context information component that provides detailed information about an execution context.

Implements: IReconfigurable

Description

The ContextInfo class allows you to create context information components that provide detailed information about execution contexts.

Important points

  • Most often ContextInfo is used by logging and performance counters to identify the source of the collected logs and metrics.

Configuration parameters

  • name: the context (container or process) name
  • description: human-readable description of the context
  • properties: entire section of additional descriptive properties

Constructors

Creates a new instance of this context info.

public constructor(name?: string, description?: string)

  • name: string - (optional) a context name.
  • description: string - (optional) a human-readable description of the context.

Properties

contextId

Gets the unique context id. Usually it is the current host name.

public contextId(): string

  • returns: string - the unique context id.

Gets the unique context id. Usually it is the current host name.

public contextId(context_id: string)

  • contextId: string - the unique context id.

description

Gets the human-readable description of the context.

public description(): string

  • returns: string - the human-readable description of the context.

Sets the human-readable description of the context.

public description(description: string)

  • description: string - a new human readable description of the context.

name

Gets the context name.

public name(): string

  • returns: string - the context name

Sets the context name.

public name(name: string)

  • name: string - a new name for the context.

properties

Gets context additional parameters.

public properties(): any

  • returns: any - a JSON object with additional context parameters.

Sets context additional parameters.

public properties(properties: any)

  • properties: any - a JSON object with context additional parameters

startTime

Gets the context start time.

public startTime(): Date

  • returns: any - a JSON object with additional context parameters.

Sets the context start time.

public startTime(start_time: Date)

  • start_time: Date - a new context start time.

Instance methods

configure

Configures component by passing configuration parameters.

public configure(config: ConfigParams): void

  • config: ConfigParams - configuration parameters to be set.

Static methods

fromConfig

Creates a new ContextInfo and sets its configuration parameters.

public static fromConfig(config: ConfigParams): ContextInfo

  • config: ConfigParams - configuration parameters for the new ContextInfo.
  • returns: ContextInfo - a newly created ContextInfo

Examples

let contextInfo = new ContextInfo();
contextInfo.configure(ConfigParams.fromTuples(
    "name", "MyMicroservice",
    "description", "My first microservice"
));

context.name;            // Result: "MyMicroservice"
context.contextId;        // Possible result: "mylaptop"
context.startTime;        // Possible result: 2018-01-01:22:12:23.45Z
context.uptime;            // Possible result: 3454345