+++
# -----------------------------------------------------------------------
# Do not edit this file. It is automatically generated by API Documenter.
# -----------------------------------------------------------------------
title = "DataSourceApi"
keywords = ["grafana","documentation","sdk","@grafana/data"]
type = "docs"
+++
## DataSourceApi class
The main data source abstraction interface, represents an instance of a data source
Although this is a class, datasource implementations do not \*yet\* need to extend it. As such, we can not yet add functions with default implementations.
Signature
```typescript
export declare abstract class DataSourceApi
```
Import
```typescript
import { DataSourceApi } from '@grafana/data';
```
Constructors
| Constructor | Modifiers | Description |
| --- | --- | --- |
| [constructor(instanceSettings)](#constructor-instancesettings) | | Constructs a new instance of the DataSourceApi
class |
Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [components](#components-property) | | DataSourcePluginComponents<DataSourceApi<TQuery, TOptions>, TQuery, TOptions>
| Set after constructor call, as the data source instance is the most common thing to pass around we attach the components to this instance for easy access |
| [getLogRowContext](#getlogrowcontext-property) | | <TContextQueryOptions extends {}>(row: LogRowModel, options?: TContextQueryOptions) => Promise<DataQueryResponse>
| Retrieve context for a given log row |
| [id](#id-property) | | number
| Set in constructor |
| [init](#init-property) | | () => void
| Initializes a datasource after instantiation |
| [interval](#interval-property) | | string
| min interval range |
| [languageProvider](#languageprovider-property) | | any
| Used in explore |
| [meta](#meta-property) | | DataSourcePluginMeta
| static information about the datasource |
| [name](#name-property) | | string
| Set in constructor |
Methods
| Method | Modifiers | Description |
| --- | --- | --- |
| [annotationQuery(options)](#annotationquery-method) | | Can be optionally implemented to allow datasource to be a source of annotations for dashboard. To be visible in the annotation editor annotations
capability also needs to be enabled in plugin.json. |
| [getHighlighterExpression(query)](#gethighlighterexpression-method) | | Used in explore |
| [getQueryDisplayText(query)](#getquerydisplaytext-method) | | Convert a query to a simple text string |
| [getQueryHints(query, results, rest)](#getqueryhints-method) | | Get hints for query improvements |
| [getTagKeys(options)](#gettagkeys-method) | | Get tag keys for adhoc filters |
| [getTagValues(options)](#gettagvalues-method) | | Get tag values for adhoc filters |
| [getVersion(optionalOptions)](#getversion-method) | | |
| [importQueries(queries, originMeta)](#importqueries-method) | | Imports queries from a different datasource |
| [interpolateVariablesInQueries(queries, scopedVars)](#interpolatevariablesinqueries-method) | | |
| [metricFindQuery(query, options)](#metricfindquery-method) | | Variable query action. |
| [modifyQuery(query, action)](#modifyquery-method) | | Used in explore |
| [query(request)](#query-method) | | Query for data, and optionally stream results |
| [showContextToggle(row)](#showcontexttoggle-method) | | |
| [targetContainsTemplate(query)](#targetcontainstemplate-method) | | Used by alerting to check if query contains template variables |
| [testDatasource()](#testdatasource-method) | | Test & verify datasource settings & connection details |
### constructor(instanceSettings)
Constructs a new instance of the `DataSourceApi` class
Signature
```typescript
constructor(instanceSettings: DataSourceInstanceSettings);
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| instanceSettings | DataSourceInstanceSettings<TOptions>
| |
### components property
Set after constructor call, as the data source instance is the most common thing to pass around we attach the components to this instance for easy access
Signature
```typescript
components?: DataSourcePluginComponents, TQuery, TOptions>;
```
### getLogRowContext property
Retrieve context for a given log row
Signature
```typescript
getLogRowContext?: (row: LogRowModel, options?: TContextQueryOptions) => Promise;
```
### id property
Set in constructor
Signature
```typescript
readonly id: number;
```
### init property
Initializes a datasource after instantiation
Signature
```typescript
init?: () => void;
```
### interval property
min interval range
Signature
```typescript
interval?: string;
```
### languageProvider property
Used in explore
Signature
```typescript
languageProvider?: any;
```
### meta property
static information about the datasource
Signature
```typescript
meta: DataSourcePluginMeta;
```
### name property
Set in constructor
Signature
```typescript
readonly name: string;
```
### annotationQuery method
Can be optionally implemented to allow datasource to be a source of annotations for dashboard. To be visible in the annotation editor `annotations` capability also needs to be enabled in plugin.json.
Signature
```typescript
annotationQuery?(options: AnnotationQueryRequest): Promise;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| options | AnnotationQueryRequest<TQuery>
| |
Returns:
`Promise`
### getHighlighterExpression method
Used in explore
Signature
```typescript
getHighlighterExpression?(query: TQuery): string[];
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | TQuery
| |
Returns:
`string[]`
### getQueryDisplayText method
Convert a query to a simple text string
Signature
```typescript
getQueryDisplayText?(query: TQuery): string;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | TQuery
| |
Returns:
`string`
### getQueryHints method
Get hints for query improvements
Signature
```typescript
getQueryHints?(query: TQuery, results: any[], ...rest: any): QueryHint[];
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | TQuery
| |
| results | any[]
| |
| rest | any
| |
Returns:
`QueryHint[]`
### getTagKeys method
Get tag keys for adhoc filters
Signature
```typescript
getTagKeys?(options?: any): Promise;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| options | any
| |
Returns:
`Promise`
### getTagValues method
Get tag values for adhoc filters
Signature
```typescript
getTagValues?(options: any): Promise;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| options | any
| |
Returns:
`Promise`
### getVersion method
Signature
```typescript
getVersion?(optionalOptions?: any): Promise;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| optionalOptions | any
| |
Returns:
`Promise`
### importQueries method
Imports queries from a different datasource
Signature
```typescript
importQueries?(queries: TQuery[], originMeta: PluginMeta): Promise;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| queries | TQuery[]
| |
| originMeta | PluginMeta
| |
Returns:
`Promise`
### interpolateVariablesInQueries method
Signature
```typescript
interpolateVariablesInQueries?(queries: TQuery[], scopedVars: ScopedVars | {}): TQuery[];
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| queries | TQuery[]
| |
| scopedVars | ScopedVars | {}
| |
Returns:
`TQuery[]`
### metricFindQuery method
Variable query action.
Signature
```typescript
metricFindQuery?(query: any, options?: any): Promise;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | any
| |
| options | any
| |
Returns:
`Promise`
### modifyQuery method
Used in explore
Signature
```typescript
modifyQuery?(query: TQuery, action: QueryFixAction): TQuery;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | TQuery
| |
| action | QueryFixAction
| |
Returns:
`TQuery`
### query method
Query for data, and optionally stream results
Signature
```typescript
abstract query(request: DataQueryRequest): Promise | Observable;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| request | DataQueryRequest<TQuery>
| |
Returns:
`Promise | Observable`
### showContextToggle method
Signature
```typescript
showContextToggle?(row?: LogRowModel): boolean;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| row | LogRowModel
| |
Returns:
`boolean`
### targetContainsTemplate method
Used by alerting to check if query contains template variables
Signature
```typescript
targetContainsTemplate?(query: TQuery): boolean;
```
Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| query | TQuery
| |
Returns:
`boolean`
### testDatasource method
Test & verify datasource settings & connection details
Signature
```typescript
abstract testDatasource(): Promise;
```
Returns:
`Promise`